initial commit

This commit is contained in:
2025-05-22 19:39:08 +08:00
commit 531bb42d01
103 changed files with 10291 additions and 0 deletions

View 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
}