44 lines
842 B
Go
44 lines
842 B
Go
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
|
|
}
|