所有序列化, 都加入 BeforeLogic AfterLogic方法. 便于处理 w r的传递的参数
This commit is contained in:
@@ -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")
|
||||
}
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user