beegoinit/response/json/json.go
2020-07-10 10:33:13 +08:00

45 lines
717 B
Go

package json
type Json struct {
Code int `json:"code"`
Data interface{} `json:"data"`
Msg string `json:"msg"`
Status bool `json:"status"`
}
func GetDefaultJsonSuccessResponse() *Json {
return &Json{
Code: 0,
Data: nil,
Msg: "ok",
Status: true,
}
}
func GetDefaultJsonFailedResponse() *Json {
return &Json{
Code: 1,
Data: nil,
Msg: "unknow",
Status: false,
}
}
func New(status bool, code int, msg string, data ...interface{}) *Json {
if len(data) > 0 {
return &Json{
Code: code,
Data: data[0],
Msg: msg,
Status: status,
}
} else {
return &Json{
Code: code,
Data: nil,
Msg: msg,
Status: status,
}
}
}