所有序列化, 都加入 BeforeLogic AfterLogic方法. 便于处理 w r的传递的参数

This commit is contained in:
eson
2023-07-21 15:20:18 +08:00
parent 373d5dca45
commit 2825f8ae54
100 changed files with 1499 additions and 454 deletions

View File

@@ -10,6 +10,7 @@ import (
"time"
"context"
"github.com/zeromicro/go-zero/core/logx"
)
@@ -27,7 +28,7 @@ func NewGetMapLibraryListLogic(ctx context.Context, svcCtx *svc.ServiceContext)
}
}
func (l *GetMapLibraryListLogic) GetMapLibraryList(userinfo *auth.UserInfo) (resp *basic.Response) {
func (l *GetMapLibraryListLogic) GetMapLibraryList(req *types.Request, userinfo *auth.UserInfo) (resp *basic.Response) {
if userinfo.GetIdType() != auth.IDTYPE_User {
return resp.SetStatusWithMessage(basic.CodeServiceErr, "please login first")
}

View File

@@ -19,8 +19,9 @@ import (
type SaveMapLibraryLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
ctx context.Context
svcCtx *svc.ServiceContext
bodyData []byte
}
func NewSaveMapLibraryLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SaveMapLibraryLogic {
@@ -31,14 +32,31 @@ func NewSaveMapLibraryLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Sa
}
}
func (l *SaveMapLibraryLogic) SaveMapLibrary(userinfo *auth.UserInfo, r *http.Request) (resp *basic.Response) {
// 处理进入前逻辑w,r
func (l *SaveMapLibraryLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) {
bodyData, err := ioutil.ReadAll(r.Body)
defer r.Body.Close()
if err != nil {
logx.Error(err)
return
}
l.bodyData = bodyData
}
func (l *SaveMapLibraryLogic) SaveMapLibrary(req *types.Request, userinfo *auth.UserInfo) (resp *basic.Response) {
if userinfo.GetIdType() != auth.IDTYPE_User {
return resp.SetStatusWithMessage(basic.CodeServiceErr, "please login first")
}
bodyData, err := ioutil.ReadAll(r.Body)
defer r.Body.Close()
if len(l.bodyData) == 0 {
return resp.SetStatus(basic.CodeApiErr, http.ErrBodyReadAfterClose.Error())
}
var err error
var postData []types.SaveMapLibraryData
if err = json.Unmarshal(bodyData, &postData); err != nil {
if err = json.Unmarshal(l.bodyData, &postData); err != nil {
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeSaveErr, "param err")
}