Skip to content

Commit

Permalink
chore: fix lint error
Browse files Browse the repository at this point in the history
  • Loading branch information
MuZhou233 committed Sep 20, 2024
1 parent a02b30f commit 0597b79
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 60 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions app/sephirah/cmd/sephirah/wire_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

43 changes: 20 additions & 23 deletions app/sephirah/internal/service/librariansephirahservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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()
Expand All @@ -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(),
Expand Down
2 changes: 0 additions & 2 deletions app/sephirah/pkg/service/wire.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -46,6 +45,5 @@ func NewSephirahService(
client.ProviderSet,
supervisor.ProviderSet,
service.ProviderSet,
server.ProviderSet,
))
}
4 changes: 1 addition & 3 deletions app/sephirah/pkg/service/wire_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion internal/lib/libapp/stream_middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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 {
Expand Down
29 changes: 1 addition & 28 deletions internal/server/server.go
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 0597b79

Please sign in to comment.