const (
MsgSuccess = "success"
MsgFailed = "failed"
Null = ""
)
type Response struct {
Code int `json:"code"`
Msg string `json:"msg"`
Data any `json:"data"`
}
// OK 返回成功信号
func OK() Response {
return Response{
Code: http.StatusOK,
Msg: MsgSuccess,
Data: Null,
}
}
// OKWithData 返回数据响应
func OKWithData(data any) Response {
return Response{
Code: http.StatusOK,
Msg: MsgSuccess,
Data: data,
}
}
// ErrWithMsg 返回错误响应
func ErrWithMsg(msg string) Response {
return Response{
Code: http.StatusInternalServerError,
Msg: msg,
Data: Null,
}
}