initial commit
This commit is contained in:
43
gateway/internal/logic/loginlogic.go
Normal file
43
gateway/internal/logic/loginlogic.go
Normal file
@ -0,0 +1,43 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"godemo/gateway/internal/svc"
|
||||
"godemo/gateway/internal/types"
|
||||
"godemo/user/user"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type LoginLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewLoginLogic(ctx context.Context, svcCtx *svc.ServiceContext) *LoginLogic {
|
||||
return &LoginLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *LoginLogic) Login(req *types.LoginReq) (resp *types.LoginResp, err error) {
|
||||
// 调用 user RPC 的 Login 方法
|
||||
rpcResp, err := l.svcCtx.UserRpc.Login(l.ctx, &user.LoginRequest{
|
||||
Username: req.Username,
|
||||
Password: req.Password,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 构造 API 返回值
|
||||
resp = &types.LoginResp{
|
||||
Token: rpcResp.Token,
|
||||
ExpiresAt: rpcResp.ExpiresAt,
|
||||
}
|
||||
return
|
||||
}
|
||||
Reference in New Issue
Block a user