Skip to content

Commit

Permalink
feat: add custom code
Browse files Browse the repository at this point in the history
  • Loading branch information
wubenqi committed Nov 7, 2022
1 parent 339747d commit e36eaae
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 20 deletions.
5 changes: 3 additions & 2 deletions app/bff/authorization/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@ import (
"github.com/teamgram/teamgram-server/app/bff/authorization/internal/server/grpc/service"
"github.com/teamgram/teamgram-server/app/bff/authorization/internal/svc"
"github.com/teamgram/teamgram-server/app/bff/authorization/plugin"
"github.com/teamgram/teamgram-server/pkg/code"
)

type (
Config = config.Config
AuthorizationService = service.Service
)

func New(c Config, plugin plugin.AuthorizationPlugin) *service.Service {
return service.New(svc.NewServiceContext(c, plugin))
func New(c Config, code2 code.VerifyCodeInterface, plugin plugin.AuthorizationPlugin) *service.Service {
return service.New(svc.NewServiceContext(c, code2, plugin))
}
6 changes: 2 additions & 4 deletions app/bff/authorization/internal/logic/auth_logic.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ import (
"github.com/teamgram/teamgram-server/app/bff/authorization/internal/dao"
"github.com/teamgram/teamgram-server/app/bff/authorization/internal/model"
"github.com/teamgram/teamgram-server/pkg/code"
"github.com/teamgram/teamgram-server/pkg/code/conf"

"github.com/zeromicro/go-zero/core/logx"
)

Expand All @@ -36,10 +34,10 @@ type AuthLogic struct {
code.VerifyCodeInterface
}

func NewAuthSignLogic(dao *dao.Dao, code2 *conf.SmsVerifyCodeConfig) *AuthLogic {
func NewAuthSignLogic(dao *dao.Dao, code2 code.VerifyCodeInterface) *AuthLogic {
return &AuthLogic{
Dao: dao,
VerifyCodeInterface: code.NewVerifyCode(code2),
VerifyCodeInterface: code2,
}
}

Expand Down
2 changes: 1 addition & 1 deletion app/bff/authorization/internal/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (s *Server) Initialize() error {
conf.MustLoad(*configFile, &c)

logx.Infov(c)
ctx := svc.NewServiceContext(c, nil)
ctx := svc.NewServiceContext(c, nil, nil)
s.grpcSrv = grpc.New(ctx, c.RpcServerConf)

go func() {
Expand Down
8 changes: 6 additions & 2 deletions app/bff/authorization/internal/svc/service_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/teamgram/teamgram-server/app/bff/authorization/internal/dao"
"github.com/teamgram/teamgram-server/app/bff/authorization/internal/logic"
"github.com/teamgram/teamgram-server/app/bff/authorization/plugin"
"github.com/teamgram/teamgram-server/pkg/code"
)

type ServiceContext struct {
Expand All @@ -32,12 +33,15 @@ type ServiceContext struct {
Plugin plugin.AuthorizationPlugin
}

func NewServiceContext(c config.Config, plugin plugin.AuthorizationPlugin) *ServiceContext {
func NewServiceContext(c config.Config, code2 code.VerifyCodeInterface, plugin plugin.AuthorizationPlugin) *ServiceContext {
d := dao.New(c)
if code2 == nil {
code2 = code.NewVerifyCode(c.Code)
}
return &ServiceContext{
Config: c,
Dao: d,
AuthLogic: logic.NewAuthSignLogic(d, c.Code),
AuthLogic: logic.NewAuthSignLogic(d, code2),
Plugin: plugin,
}
}
25 changes: 14 additions & 11 deletions app/bff/bff/internal/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,17 +105,20 @@ func (s *Server) Initialize() error {
// authorization_helper
mtproto.RegisterRPCAuthorizationServer(
grpcServer,
authorization_helper.New(authorization_helper.Config{
RpcServerConf: c.RpcServerConf,
KV: c.KV,
Code: c.Code,
UserClient: c.BizServiceClient,
AuthsessionClient: c.AuthSessionClient,
ChatClient: c.BizServiceClient,
StatusClient: c.StatusClient,
SyncClient: c.SyncClient,
MsgClient: c.MsgClient,
}, nil))
authorization_helper.New(
authorization_helper.Config{
RpcServerConf: c.RpcServerConf,
KV: c.KV,
Code: c.Code,
UserClient: c.BizServiceClient,
AuthsessionClient: c.AuthSessionClient,
ChatClient: c.BizServiceClient,
StatusClient: c.StatusClient,
SyncClient: c.SyncClient,
MsgClient: c.MsgClient,
},
nil,
nil))

// premium_helper
mtproto.RegisterRPCPremiumServer(
Expand Down

0 comments on commit e36eaae

Please sign in to comment.