修改对应app的参数结构
This commit is contained in:
10
utils/basic/error_code.go
Normal file
10
utils/basic/error_code.go
Normal 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
41
utils/basic/types.go
Normal 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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user