修改对应app的参数结构

This commit is contained in:
2024-04-09 13:38:29 +08:00
parent 8b7b138ca2
commit 578d7ecdf9
16 changed files with 605 additions and 78 deletions

10
utils/basic/error_code.go Normal file
View File

@@ -0,0 +1,10 @@
package basic
type ErrorCode struct {
Code int `json:"code"`
Message string `json:"message"`
}
var (
ErrParamParse = &ErrorCode{Code: 10100, Message: "参数解析错误"}
)

41
utils/basic/types.go Normal file
View File

@@ -0,0 +1,41 @@
package basic
// 全局返回的结构体
type Response struct {
Data interface{} `json:"data"`
ErrorCode int `json:"error_code"`
ErrorText string `json:"error_text"`
IsSuccess bool `json:"success"`
}
func (resp *Response) Error(errcode *ErrorCode, Data ...interface{}) {
resp.ErrorCode = errcode.Code
resp.ErrorText = errcode.Message
resp.IsSuccess = false
resp.setData(Data)
}
func (resp *Response) ErrorEx(Code int, Message string, Data ...interface{}) {
resp.ErrorCode = Code
resp.ErrorText = Message
resp.IsSuccess = false
resp.setData(Data)
}
func (resp *Response) Success(Data ...interface{}) {
resp.IsSuccess = true
resp.setData(Data)
}
func (resp *Response) setData(Data []interface{}) {
if len(Data) == 0 {
resp.Data = []interface{}{}
return
}
if len(Data) == 1 {
resp.Data = Data
} else {
resp.Data = Data
}
}