1 Star 0 Fork 1

爱狸狸爱生活 / goboot

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
error.go 839 Bytes
一键复制 编辑 原始数据 按行查看 历史
package middle
import (
"github.com/gin-gonic/gin"
"net/http"
)
type Error struct {
StatusCode int `json:"-"`
Code int `json:"code"`
Msg string `json:"msg"`
}
var (
Success = NewError(http.StatusOK, 0, "success")
ServerError = NewError(http.StatusInternalServerError, 200500, "系统异常,请稍后重试!")
NotFound = NewError(http.StatusNotFound, 200404, http.StatusText(http.StatusNotFound))
)
func OtherError(message string) *Error {
return NewError(http.StatusForbidden, 100403, message)
}
func (e *Error) Error() string {
return e.Msg
}
func NewError(statusCode, Code int, msg string) *Error {
return &Error{
StatusCode: statusCode,
Code: Code,
Msg: msg,
}
}
// 404处理
func HandleNotFound(c *gin.Context) {
err := NotFound
c.JSON(err.StatusCode, err)
return
}
Go
1
https://gitee.com/ixxyy/goboot.git
git@gitee.com:ixxyy/goboot.git
ixxyy
goboot
goboot
v0.1.27

搜索帮助