PersonalMain-Golang/utility/ResultUtil.go
2023-12-25 02:19:00 +08:00

51 lines
1.0 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package utility
import (
"PersonalMain/utility/ErrorCode"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/net/ghttp"
)
type DataResult struct{}
// Success
//
// 内容输出(包含 data
func Success(req *ghttp.Request, message string, data interface{}) {
req.Response.WriteJson(g.Map{
"output": "Success",
"code": 200,
"message": message,
"data": data,
})
}
// SuccessNoData
//
// 内容输出(不含 data
func SuccessNoData(req *ghttp.Request, message string) {
req.Response.WriteJson(g.Map{
"output": "Success",
"code": 200,
"message": message,
})
}
func Error(req *ghttp.Request, errorCode ErrorCode.ErrorCode, data interface{}) {
req.Response.WriteJson(g.Map{
"output": errorCode.Output(),
"code": errorCode.Code(),
"message": errorCode.Message(),
"data": data,
})
}
func ErrorDefault(req *ghttp.Request, output string, code int, message string, data interface{}) {
req.Response.WriteJson(g.Map{
"output": output,
"code": code,
"message": message,
"data": data,
})
}