Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // 请求不合法 ErrBadRequest = NewAPIException(http.StatusBadRequest, http.StatusText(http.StatusBadRequest)). WithHttpCode(http.StatusBadRequest). WithMessage("请求不合法") ErrUnauthorized = NewAPIException(http.StatusUnauthorized, http.StatusText(http.StatusUnauthorized)). WithHttpCode(http.StatusUnauthorized). WithMessage("请先登录") // 鉴权失败, 认证通过,但是没有权限操作 该接口 ErrPermissionDeny = NewAPIException(http.StatusForbidden, http.StatusText(http.StatusForbidden)). WithHttpCode(http.StatusForbidden). WithMessage("无权限访问") )
Functions ¶
Types ¶
type APIException ¶
type APIException struct { HttpCode int `json:"-"` Code int `json:"code"` Reason string `json:"reason"` Message string `json:"message"` }
error的自定义实现 通过 API 直接序列号化{}
func NewAPIException ¶
func NewAPIException(code int, Reason string) *APIException
func (*APIException) Error ¶
func (e *APIException) Error() string
func (*APIException) WithHttpCode ¶
func (e *APIException) WithHttpCode(code int) *APIException
设计为链式调用 New().WithHttpCode()
func (*APIException) WithMessage ¶
func (e *APIException) WithMessage(msg string) *APIException
设计为链式调用 New().WithMessage()
func (*APIException) WithMessagef ¶
func (e *APIException) WithMessagef(format string, a ...any) *APIException
设计为链式调用 New().WithMessagef()
Click to show internal directories.
Click to hide internal directories.