You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
66 lines
1.3 KiB
66 lines
1.3 KiB
package dto
|
|
|
|
import (
|
|
"github.com/gogf/gf/v2/frame/g"
|
|
)
|
|
|
|
// 定义响应结构
|
|
type Result struct {
|
|
Code int `json:"code"`
|
|
Message string `json:"message"`
|
|
Data interface{} `json:"data"` // 修改为实体类型
|
|
}
|
|
|
|
/*成功,没有数据*/
|
|
func Success() *Result {
|
|
return &Result{
|
|
Code: 200,
|
|
Message: "success",
|
|
Data: g.Map{},
|
|
}
|
|
}
|
|
|
|
/*成功,有数据*/
|
|
func SuccessWithData(data interface{}) *Result {
|
|
return &Result{
|
|
Code: 200,
|
|
Message: "success",
|
|
Data: data,
|
|
}
|
|
}
|
|
|
|
/*错误,只有错误信息,错误码0*/
|
|
func Error(msg string) *Result {
|
|
return &Result{
|
|
Code: 0, // 错误码
|
|
Message: msg, // 错误信息
|
|
Data: g.Map{},
|
|
}
|
|
}
|
|
|
|
/*错误,有错误信息,有错误码*/
|
|
func ErrorWithCode(code int, msg string) *Result {
|
|
return &Result{
|
|
Code: code, // 错误码
|
|
Message: msg, // 错误信息
|
|
Data: g.Map{},
|
|
}
|
|
}
|
|
|
|
/*未授权,有错误信息,错误码为401*/
|
|
func Unauthorized(msg string) *Result {
|
|
return &Result{
|
|
Code: 401, // 错误码
|
|
Message: msg, // 错误信息
|
|
Data: g.Map{},
|
|
}
|
|
}
|
|
|
|
/*未授权,有错误信息,允许自定义错误码*/
|
|
func UnauthorizedWithCode(code int, msg string) *Result {
|
|
return &Result{
|
|
Code: code, // 错误码
|
|
Message: msg, // 错误信息
|
|
Data: g.Map{},
|
|
}
|
|
}
|