2023-02-26 02:50:56 +08:00
|
|
|
package resp
|
|
|
|
|
|
|
|
type Response struct {
|
2023-02-28 00:03:02 +08:00
|
|
|
// 状态码
|
|
|
|
Code Code `json:"code" example:"200"`
|
|
|
|
// 数据
|
2023-02-26 02:50:56 +08:00
|
|
|
Data interface{} `json:"data"`
|
2023-02-28 00:03:02 +08:00
|
|
|
// 信息
|
|
|
|
Msg string `json:"msg" example:"OK"`
|
2023-02-26 02:50:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
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",
|
|
|
|
}
|
|
|
|
}
|