You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
41 lines
757 B
Go
41 lines
757 B
Go
package models
|
|
|
|
type Response struct {
|
|
Code int `form:"code" json:"code" uri:"code" xml:"code"`
|
|
Msg string `form:"msg" json:"msg" uri:"msg" xml:"msg"`
|
|
Data interface{} `form:"data" json:"data" uri:"data" xml:"data"`
|
|
}
|
|
|
|
func (r *Response) Init() *Response {
|
|
r.Code = 500
|
|
r.Msg = "none"
|
|
return r
|
|
}
|
|
|
|
func (r *Response) SetData(i interface{}) *Response {
|
|
r.Code = 200
|
|
r.Data = i
|
|
return r
|
|
}
|
|
|
|
func (r *Response) Success() *Response {
|
|
r.Code = 200
|
|
r.Msg = "success"
|
|
return r
|
|
}
|
|
|
|
func (r *Response) Error(msg string) *Response {
|
|
r.Code = 500
|
|
r.Msg = msg
|
|
return r
|
|
}
|
|
|
|
func (r *Response) CheckErr(err error) *Response {
|
|
if err != nil {
|
|
r.Code = 500
|
|
r.Msg = err.Error()
|
|
return r
|
|
}
|
|
return r
|
|
}
|