1 Star 0 Fork 0

霖宇长清/cloud-gin-manager

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
user.go 1.24 KB
一键复制 编辑 原始数据 按行查看 历史
package serializer
import "gitee.com/LangHuaHuachihua/cloud-gin-manager/models"
// User 用户序列化器
type User struct {
ID uint `json:"id"`
UserName string `json:"user_name"`
Nickname string `json:"nickname"`
Status string `json:"status"`
Avatar string `json:"avatar"`
CreatedAt int64 `json:"created_at"`
Token string `json:"token"`
}
// BuildUser 序列化用户
func BuildLoginUser(user models.User, token string) User {
return User{
ID: user.ID,
UserName: user.UserName,
Nickname: user.Nickname,
Status: user.Status,
Avatar: user.Avatar,
CreatedAt: user.CreatedAt.Unix(),
Token: token,
}
}
func BuildRegisterUser(user models.User) User {
return User{
ID: user.ID,
UserName: user.UserName,
Nickname: user.Nickname,
Status: user.Status,
Avatar: user.Avatar,
CreatedAt: user.CreatedAt.Unix(),
}
}
// BuildUserResponse 序列化用户响应
func BuildRegisterUserResponse(user models.User, code int) Response {
return Response{
Data: BuildRegisterUser(user),
Msg: "ok",
Code: code,
}
}
func BuildLoginUserResponse(user models.User, token string, code int) Response {
return Response{
Data: BuildLoginUser(user, token),
Msg: "ok",
Code: code,
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/LangHuaHuachihua/cloud-gin-manager.git
git@gitee.com:LangHuaHuachihua/cloud-gin-manager.git
LangHuaHuachihua
cloud-gin-manager
cloud-gin-manager
97a7533c2978

搜索帮助