From 5c90f4f3d566e74f4734c58ed0ba1bbaee4ab087 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Sterba?= <hda@andre-sterba.de> Date: Thu, 17 Apr 2025 15:08:15 +0000 Subject: [PATCH] Resolve "Enable linter to catch unused fields and let them fail lint" --- .golangci.yaml | 11 ++++++++++- ctrl/internal/infrastructure/grpc/server.go | 5 ++--- ctrl/internal/service/routing.go | 9 +++++++++ 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/.golangci.yaml b/.golangci.yaml index 2ea353eb..10a8202c 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -16,7 +16,7 @@ linters: - nestif - paralleltest - protogetter - - testifylint + - testifylint - whitespace - durationcheck - bodyclose @@ -28,6 +28,15 @@ linters: - sqlclosecheck #- exhaustruct # Does not work with gRPC, as it wants us to implement 'UnimplementedHealthCtrlServer', which is obviously not intended to be implemented. Would otherwise be useful. + settings: + unused: + # Mark all function parameters as used. + parameters-are-used: false + # Mark all local variables as used. + local-variables-are-used: false + # Mark all identifiers inside generated files as used. + generated-is-used: false + formatters: # Enable specific formatter. # Default: [] (uses standard Go formatting) diff --git a/ctrl/internal/infrastructure/grpc/server.go b/ctrl/internal/infrastructure/grpc/server.go index 97539372..10dd7b8a 100644 --- a/ctrl/internal/infrastructure/grpc/server.go +++ b/ctrl/internal/infrastructure/grpc/server.go @@ -19,7 +19,7 @@ import ( // It is used to start the server and register services. // It also implements the io.Closer interface to allow for graceful shutdown. type GRPCServer interface { - Start(serviceRegister func(server *grpc.Server, app *application.Application)) + Start(func(server *grpc.Server, app *application.Application)) io.Closer } @@ -35,7 +35,7 @@ func NewGrpcServer( app *application.Application, logger *zap.SugaredLogger, ) (GRPCServer, error) { - options, err := buildOptions(config, logger) + options, err := buildOptions(logger) if err != nil { return nil, err } @@ -71,7 +71,6 @@ func (g gRPCServer) Close() error { } func buildOptions( - config config.Config, logs *zap.SugaredLogger, ) ([]grpc.ServerOption, error) { grpcPanicRecoveryHandler := func(p any) (err error) { diff --git a/ctrl/internal/service/routing.go b/ctrl/internal/service/routing.go index 1ed3c881..c6217969 100644 --- a/ctrl/internal/service/routing.go +++ b/ctrl/internal/service/routing.go @@ -32,6 +32,8 @@ func (r *Routing) RequestRoute( // calculate route time.Sleep(time.Second) + r.logger.Debugf("got request route %+v", req) + return model.Route{ ID: "1337", }, nil @@ -45,6 +47,7 @@ func (r *Routing) AnnouncePayloadRelay( defer span.End() // gossip routes to KMS + r.logger.Debugf("got announce payload relay %+v", req) return nil } @@ -56,6 +59,8 @@ func (r *Routing) PayloadRelayFinished( _, span := r.tracer.Start(ctx, "payload-relay-finished") defer span.End() + r.logger.Debugf("got payload relay finished %+v", req) + return nil } @@ -63,6 +68,8 @@ func (r *Routing) PayloadRelayError(ctx context.Context, req ports.PayloadRelayE _, span := r.tracer.Start(ctx, "payload-relay-error") defer span.End() + r.logger.Debugf("got payload relay error %+v", req) + return nil } @@ -73,5 +80,7 @@ func (r *Routing) PushKeyStoreFillLevel( _, span := r.tracer.Start(ctx, "push-key-store-fill-level") defer span.End() + r.logger.Debugf("got push key store fill level %+v", req) + return nil } -- GitLab