finish: gorm序列化

This commit is contained in:
eson
2023-06-14 18:17:45 +08:00
parent 50bca808f1
commit 6a2cfb14e9
26 changed files with 841 additions and 143 deletions

View File

@@ -15,28 +15,40 @@ import (
func {{.HandlerName}}(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
// jwtToken
var (
//
err error
//
userinfo *auth.UserInfo
)
// JWT token,
claims, err := svcCtx.ParseJwtToken(r)
// JSON响应并记录错误消息
// JWT token出错,JSON响应并记录错误消息
if err != nil {
httpx.OkJsonCtx(r.Context(), w, &basic.Response{
Code: 401,
Message: "unauthorized",
Code: 401, // 401,
Message: "unauthorized", //
})
logx.Info("unauthorized:", err.Error())
logx.Info("unauthorized:", err.Error()) //
return
}
// Token里获取对应的信息
userinfo, err := auth.GetUserInfoFormMapClaims(claims)
// JSON响应并记录错误消息
if err != nil {
httpx.OkJsonCtx(r.Context(), w, &basic.Response{
Code: 401,
Message: "unauthorized",
})
logx.Info("unauthorized:", err.Error())
return
if claims != nil {
// token中获取对应的用户信息
userinfo, err = auth.GetUserInfoFormMapClaims(claims)
// ,JSON响应并记录错误消息
if err != nil {
httpx.OkJsonCtx(r.Context(), w, &basic.Response{
Code: 401,
Message: "unauthorized",
})
logx.Info("unauthorized:", err.Error())
return
}
} else {
// claims为nil,
userinfo = &auth.UserInfo{UserId: 0, GuestId: 0}
}
{{if .HasRequest}}var req types.{{.RequestType}}
@@ -53,7 +65,6 @@ func {{.HandlerName}}(svcCtx *svc.ServiceContext) http.HandlerFunc {
{{end}}l := {{.LogicName}}.New{{.LogicType}}(r.Context(), svcCtx)
{{if .HasResp}}resp{{end}} := l.{{.Call}}({{if .HasRequest}}&req, {{end}}userinfo)
// nil使httpx.OkJsonCtx方法返回JSON响应;
// 500JSON响应并记录错误消息logx.Error
if resp != nil {
{{if .HasResp}}httpx.OkJsonCtx(r.Context(), w, resp){{else}}httpx.Ok(w){{end}}
} else {