41 lines
662 B
Go
41 lines
662 B
Go
package resp
|
|
|
|
type Response struct {
|
|
Code Code `json:"code" example:"200"`
|
|
Data interface{} `json:"data"`
|
|
Msg string `json:"msg" example:"OK"`
|
|
}
|
|
|
|
type Code = int
|
|
|
|
const (
|
|
SUCCESS = 200
|
|
UNAUTHORIZED = 401
|
|
FORBIDDEN = 403
|
|
ERROR = 500
|
|
)
|
|
|
|
func NewCustomResponse(code int, data interface{}, msg string) *Response {
|
|
return &Response{
|
|
Code: code,
|
|
Data: data,
|
|
Msg: msg,
|
|
}
|
|
}
|
|
|
|
func NewResponseWithCode(code int, data interface{}) *Response {
|
|
return &Response{
|
|
Code: SUCCESS,
|
|
Data: data,
|
|
Msg: "OK",
|
|
}
|
|
}
|
|
|
|
func NewResponse(data interface{}) *Response {
|
|
return &Response{
|
|
Code: SUCCESS,
|
|
Data: data,
|
|
Msg: "OK",
|
|
}
|
|
}
|