From 85f07ec14a80606afc5d19ac75ffafe7a1ef6b34 Mon Sep 17 00:00:00 2001 From: Christian Schaible Date: Mon, 15 Jul 2024 12:16:44 +0200 Subject: [PATCH] Fix linter issues --- README.md | 2 +- audit/api/api_legacy.go | 2 -- audit/api/api_routable_test.go | 4 ---- audit/messaging/messaging.go | 4 ++-- audit/messaging/solace.go | 19 +++++++++---------- 5 files changed, 12 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 1ec1ff8..96e4525 100644 --- a/README.md +++ b/README.md @@ -144,7 +144,7 @@ buf generate --include-imports ##### Build library ```bash -go mod download && go mod tidy && go get ./... && go fmt ./... && go vet ./... && go build ./... && go test ./... +go mod download && go mod tidy && go get ./... && go fmt ./... && go vet ./... && golangci-lint run && go build ./... && go test ./... ``` #### Register buf validation schema in IntelliJ / Goland diff --git a/audit/api/api_legacy.go b/audit/api/api_legacy.go index 8816b4e..ad515bc 100644 --- a/audit/api/api_legacy.go +++ b/audit/api/api_legacy.go @@ -229,11 +229,9 @@ func (a *LegacyAuditApi) convertAndSerializeIntoLegacyFormat( } else { return nil, ErrUnsupportedObjectIdentifierType } - break case *auditV1.RoutableAuditEvent_ObjectName: eventType = "SYSTEM_EVENT" messageContext = nil - break default: return nil, ErrUnsupportedResourceReferenceType } diff --git a/audit/api/api_routable_test.go b/audit/api/api_routable_test.go index e0a8c31..cb42489 100644 --- a/audit/api/api_routable_test.go +++ b/audit/api/api_routable_test.go @@ -410,15 +410,12 @@ func validateProtobufMessagePayload( if objectIdentifier.Type == auditV1.ObjectType_OBJECT_TYPE_ORGANIZATION { assert.Equal(t, routingIdentifier.Identifier.String(), reference.ObjectIdentifier.Identifier) } - break case RoutingIdentifierTypeProject: assert.Equal(t, routingIdentifier.Identifier.String(), reference.ObjectIdentifier.Identifier) assert.Equal(t, auditV1.ObjectType_OBJECT_TYPE_PROJECT, reference.ObjectIdentifier.Type) - break default: assert.Fail(t, "Routing identifier type not expected") } - break case *auditV1.RoutableAuditEvent_ObjectName: assert.Nil(t, objectIdentifier) assert.Nil(t, routingIdentifier) @@ -431,7 +428,6 @@ func validateProtobufMessagePayload( switch data := routableAuditEvent.Data.(type) { case *auditV1.RoutableAuditEvent_UnencryptedData: assert.NoError(t, proto.Unmarshal(data.UnencryptedData.Data, &auditEvent)) - break default: assert.Fail(t, "Encrypted data not expected") } diff --git a/audit/messaging/messaging.go b/audit/messaging/messaging.go index e64e9cd..af52849 100644 --- a/audit/messaging/messaging.go +++ b/audit/messaging/messaging.go @@ -131,7 +131,7 @@ func (a *AmqpMessagingApi) Send(ctx context.Context, topic string, data []byte, } // Drop the current sender, as it cannot connect to the broker anymore - slog.Error("message sender error, recreating", err) + slog.Error("message sender error, recreating", slog.Any("error", err)) err = a.resetConnection(ctx) if err != nil { @@ -182,7 +182,7 @@ func (a *AmqpMessagingApi) resetConnection(ctx context.Context) error { _ = (*a.session).Close(ctx) err := a.connection.Close() if err != nil { - slog.Error("failed to close message connection", err) + slog.Error("failed to close message connection", slog.Any("error", err)) } return a.connect() diff --git a/audit/messaging/solace.go b/audit/messaging/solace.go index b704db0..102d65a 100644 --- a/audit/messaging/solace.go +++ b/audit/messaging/solace.go @@ -125,7 +125,8 @@ func (c SolaceContainer) QueueCreate(ctx context.Context, queueName string) erro _, err := c.sempClient.RequestWithBody( ctx, "POST", - fmt.Sprintf("/config/msgVpns/default/queues"), queueConfig) + "/config/msgVpns/default/queues", + queueConfig) return err } @@ -220,7 +221,7 @@ func (c SolaceContainer) ValidateTopicName(topicSubscriptionTopicPattern string, } // Check topic name - allowedTopicCharacters, err := regexp.Compile("[0-9A-Za-z-.]+(?:/[0-9A-Za-z-.]+)+|[0-9A-Za-z-.]+") + allowedTopicCharacters, err := regexp.Compile(`[0-9A-Za-z-.]+(?:/[0-9A-Za-z-.]+)+|[0-9A-Za-z-.]+`) if err != nil { return err } @@ -230,7 +231,7 @@ func (c SolaceContainer) ValidateTopicName(topicSubscriptionTopicPattern string, // Check topic subscription topic pattern allowedTopicSubscriptionCharacters, err := regexp.Compile( - "(?:(?:[0-9A-Za-z-.]+|[0-9A-Za-z-.]*\\*)(?:/(?:[0-9A-Za-z-.]+|[0-9A-Za-z-.]*\\*))+|(?:[0-9A-Za-z-.]+|[0-9A-Za-z-.]*\\*)|/>)|>") + `(?:(?:[0-9A-Za-z-.]+|[0-9A-Za-z-.]*\*)(?:/(?:[0-9A-Za-z-.]+|[0-9A-Za-z-.]*\*))+|(?:[0-9A-Za-z-.]+|[0-9A-Za-z-.]*\*)|/>)|>`) if err != nil { return err } @@ -257,27 +258,25 @@ func (c SolaceContainer) ValidateTopicName(topicSubscriptionTopicPattern string, case '*': if name[i] == '/' { expectedNextCharacter = '/' - nextError = errors.New(fmt.Sprintf("Invalid character '/' at index %d", i)) + nextError = fmt.Errorf("invalid character '/' at index %d", i) subscriptionIndex++ } - break case '/': if name[i] != '/' { - return errors.New(fmt.Sprintf("Expected character '/', got %c at index %d", name[i], i)) + return fmt.Errorf("expected character '/', got %c at index %d", name[i], i) } subscriptionIndex++ - break case '>': // everything is allowed break default: if name[i] != topicSubscriptionTopicPattern[subscriptionIndex] { - return errors.New(fmt.Sprintf( - "Expected character %c, got %c at index %d", + return fmt.Errorf( + "expected character %c, got %c at index %d", topicSubscriptionTopicPattern[subscriptionIndex], name[i], i, - )) + ) } else { subscriptionIndex++ }