feat: 添加版本和构建时间变量 fix: 修正短信队列类型注释错误 style: 清理未使用的代码和测试文件 docs: 更新安装文档中的下载链接 chore: 迁移数据库脚本添加日志和订阅配置
41 lines
818 B
Go
41 lines
818 B
Go
package result
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/pkg/errors"
|
|
|
|
"github.com/perfect-panel/server/pkg/xerr"
|
|
)
|
|
|
|
// HttpResult HTTP Result
|
|
func HttpResult(ctx *gin.Context, resp interface{}, err error) {
|
|
|
|
if err == nil {
|
|
// Success Result
|
|
ctx.JSON(http.StatusOK, Success(resp))
|
|
return
|
|
}
|
|
|
|
// Init Error Code and Message
|
|
code := xerr.ERROR
|
|
msg := "Internal Server Error"
|
|
|
|
// Get Error Type
|
|
var e *xerr.CodeError
|
|
if errors.As(errors.Cause(err), &e) {
|
|
// Custom Code Error
|
|
code = e.GetErrCode()
|
|
msg = e.GetErrMsg()
|
|
}
|
|
ctx.JSON(http.StatusOK, Error(code, msg))
|
|
}
|
|
|
|
// ParamErrorResult Param Error Result
|
|
func ParamErrorResult(ctx *gin.Context, err error) {
|
|
errMsg := err.Error()
|
|
_ = ctx.Error(errors.New(errMsg))
|
|
ctx.JSON(http.StatusOK, Error(xerr.InvalidParams, errMsg))
|
|
}
|