From 0597b79d6d76805b7c7065156976828715459836 Mon Sep 17 00:00:00 2001 From: MuZhou233 Date: Fri, 20 Sep 2024 14:02:12 +0800 Subject: [PATCH] chore: fix lint error --- Makefile | 2 +- app/sephirah/cmd/sephirah/wire_gen.go | 3 +- .../service/librariansephirahservice.go | 43 +++++++++---------- app/sephirah/pkg/service/wire.go | 2 - app/sephirah/pkg/service/wire_gen.go | 4 +- internal/lib/libapp/stream_middleware.go | 3 +- internal/server/server.go | 29 +------------ 7 files changed, 26 insertions(+), 60 deletions(-) diff --git a/Makefile b/Makefile index 1a3ef652..0e91a446 100644 --- a/Makefile +++ b/Makefile @@ -24,7 +24,7 @@ init: init-lint go install github.com/go-kratos/kratos/cmd/kratos/v2@latest init-lint: - go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.60.3 + go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest init-test: cd tests && make init diff --git a/app/sephirah/cmd/sephirah/wire_gen.go b/app/sephirah/cmd/sephirah/wire_gen.go index cdcb7b03..fc0af4d2 100644 --- a/app/sephirah/cmd/sephirah/wire_gen.go +++ b/app/sephirah/cmd/sephirah/wire_gen.go @@ -164,8 +164,7 @@ func wireApp(sephirahServer *conf.SephirahServer, database *conf.Database, s3 *c cleanup() return nil, nil, err } - v := server.NewAuthMiddleware(libauthAuth) - librarianSephirahServiceServer := service.NewLibrarianSephirahServiceService(angela, tiphereth, gebura, binah, yesod, netzach, chesed, supervisorSupervisor, settings, libauthAuth, v, sephirahServer) + librarianSephirahServiceServer := service.NewLibrarianSephirahServiceService(angela, tiphereth, gebura, binah, yesod, netzach, chesed, supervisorSupervisor, settings, libauthAuth, sephirahServer) grpcServer, err := server.NewGRPCServer(sephirahServer, libauthAuth, librarianSephirahServiceServer, settings, builtInObserver) if err != nil { cleanup2() diff --git a/app/sephirah/internal/service/librariansephirahservice.go b/app/sephirah/internal/service/librariansephirahservice.go index 78b3140f..7acddb06 100644 --- a/app/sephirah/internal/service/librariansephirahservice.go +++ b/app/sephirah/internal/service/librariansephirahservice.go @@ -24,17 +24,16 @@ import ( type LibrarianSephirahServiceService struct { pb.UnimplementedLibrarianSephirahServiceServer - t *biztiphereth.Tiphereth - g *bizgebura.Gebura - b *bizbinah.Binah - y *bizyesod.Yesod - n *biznetzach.Netzach - c *bizchesed.Chesed - s *supervisor.Supervisor - app *libapp.Settings - auth *libauth.Auth - authFunc func(context.Context) (context.Context, error) - info *pb.ServerInstanceSummary + t *biztiphereth.Tiphereth + g *bizgebura.Gebura + b *bizbinah.Binah + y *bizyesod.Yesod + n *biznetzach.Netzach + c *bizchesed.Chesed + s *supervisor.Supervisor + app *libapp.Settings + auth *libauth.Auth + info *pb.ServerInstanceSummary } func NewLibrarianSephirahServiceService( @@ -48,7 +47,6 @@ func NewLibrarianSephirahServiceService( s *supervisor.Supervisor, app *libapp.Settings, auth *libauth.Auth, - authFunc func(context.Context) (context.Context, error), config *conf.SephirahServer, ) pb.LibrarianSephirahServiceServer { t.CreateConfiguredAdmin() @@ -60,17 +58,16 @@ func NewLibrarianSephirahServiceService( } res := &LibrarianSephirahServiceService{ UnimplementedLibrarianSephirahServiceServer: pb.UnimplementedLibrarianSephirahServiceServer{}, - t: t, - g: g, - b: b, - y: y, - n: n, - c: c, - s: s, - app: app, - auth: auth, - authFunc: authFunc, - info: nil, + t: t, + g: g, + b: b, + y: y, + n: n, + c: c, + s: s, + app: app, + auth: auth, + info: nil, } res.info = &pb.ServerInstanceSummary{ Name: config.GetInfo().GetName(), diff --git a/app/sephirah/pkg/service/wire.go b/app/sephirah/pkg/service/wire.go index fe802d98..f3f9af17 100644 --- a/app/sephirah/pkg/service/wire.go +++ b/app/sephirah/pkg/service/wire.go @@ -16,7 +16,6 @@ import ( "github.com/tuihub/librarian/internal/lib/libcache" "github.com/tuihub/librarian/internal/lib/libcron" "github.com/tuihub/librarian/internal/lib/libmq" - "github.com/tuihub/librarian/internal/server" miner "github.com/tuihub/protos/pkg/librarian/miner/v1" searcher "github.com/tuihub/protos/pkg/librarian/searcher/v1" @@ -46,6 +45,5 @@ func NewSephirahService( client.ProviderSet, supervisor.ProviderSet, service.ProviderSet, - server.ProviderSet, )) } diff --git a/app/sephirah/pkg/service/wire_gen.go b/app/sephirah/pkg/service/wire_gen.go index 012b6593..20d01aa2 100644 --- a/app/sephirah/pkg/service/wire_gen.go +++ b/app/sephirah/pkg/service/wire_gen.go @@ -24,7 +24,6 @@ import ( "github.com/tuihub/librarian/internal/lib/libcache" "github.com/tuihub/librarian/internal/lib/libcron" "github.com/tuihub/librarian/internal/lib/libmq" - "github.com/tuihub/librarian/internal/server" v1_2 "github.com/tuihub/protos/pkg/librarian/miner/v1" "github.com/tuihub/protos/pkg/librarian/searcher/v1" v1_3 "github.com/tuihub/protos/pkg/librarian/sephirah/v1" @@ -116,8 +115,7 @@ func NewSephirahService(sephirahServer *conf.SephirahServer, database *conf.Data cleanup() return nil, nil, err } - v := server.NewAuthMiddleware(auth) - librarianSephirahServiceServer := service.NewLibrarianSephirahServiceService(angela, tiphereth, gebura, binah, yesod, netzach, chesed, supervisorSupervisor, settings, auth, v, sephirahServer) + librarianSephirahServiceServer := service.NewLibrarianSephirahServiceService(angela, tiphereth, gebura, binah, yesod, netzach, chesed, supervisorSupervisor, settings, auth, sephirahServer) return librarianSephirahServiceServer, func() { cleanup() }, nil diff --git a/internal/lib/libapp/stream_middleware.go b/internal/lib/libapp/stream_middleware.go index 918201c8..532e3c81 100644 --- a/internal/lib/libapp/stream_middleware.go +++ b/internal/lib/libapp/stream_middleware.go @@ -9,6 +9,7 @@ import ( jwtv5 "github.com/golang-jwt/jwt/v5" ) +// NewStreamMiddlewareJwt https://github.com/go-kratos/kratos/issues/2617 func NewStreamMiddlewareJwt(auth *libauth.Auth) func(ctx context.Context) (context.Context, error) { m := jwt.Server( auth.KeyFunc(libauth.ClaimsTypeUploadToken), @@ -18,7 +19,7 @@ func NewStreamMiddlewareJwt(auth *libauth.Auth) func(ctx context.Context) (conte return func(ctx context.Context) (context.Context, error) { resp := context.Background() _, err := (m(func(ctx context.Context, _ interface{}) (interface{}, error) { - resp = ctx + resp = ctx //nolint:fatcontext // no need return nil, nil }))(ctx, nil) if err != nil { diff --git a/internal/server/server.go b/internal/server/server.go index d5e1618f..95ba7cd7 100644 --- a/internal/server/server.go +++ b/internal/server/server.go @@ -1,35 +1,8 @@ package server import ( - "context" - - "github.com/tuihub/librarian/internal/lib/libauth" - - "github.com/go-kratos/kratos/v2/middleware/auth/jwt" - jwtv5 "github.com/golang-jwt/jwt/v5" "github.com/google/wire" ) // ProviderSet is server providers. -var ProviderSet = wire.NewSet(NewGRPCServer, NewGrpcWebServer, NewAuthMiddleware) - -// NewAuthMiddleware https://github.com/go-kratos/kratos/issues/2617 -func NewAuthMiddleware(auth *libauth.Auth) func(context.Context) (context.Context, error) { - return func(ctx context.Context) (context.Context, error) { - var newContext context.Context - mw := jwt.Server( - auth.KeyFunc(libauth.ClaimsTypeAccessToken), - jwt.WithSigningMethod(jwtv5.SigningMethodHS256), - jwt.WithClaims(libauth.NewClaims), - ) - handler := mw(func(ctx context.Context, req interface{}) (interface{}, error) { - newContext = ctx - return nil, nil - }) - _, err := handler(ctx, nil) - if err != nil { - return ctx, err - } - return newContext, nil - } -} +var ProviderSet = wire.NewSet(NewGRPCServer, NewGrpcWebServer)