代码拉取完成,页面将自动刷新
package code
import (
"net/http"
"gitee.com/neuro-netw0rk/server-golib/errors"
"github.com/novalagung/gubrak"
)
type ErrCode struct {
// C refers to the code of the ErrCode.
C int
// HTTP status that should be used for the associated error code.
HTTP int
// External (user) facing error text.
Ext string
// Ref specify the reference document.
Ref string
}
var _ errors.Coder = &ErrCode{}
// Code returns the integer code of ErrCode.
func (coder ErrCode) Code() int {
return coder.C
}
// String implements stringer. String returns the external error message,
// if any.
func (coder ErrCode) String() string {
return coder.Ext
}
// Reference returns the reference document.
func (coder ErrCode) Reference() string {
return coder.Ref
}
// HTTPStatus returns the associated HTTP status code, if any. Otherwise,
// returns 200.
func (coder ErrCode) HTTPStatus() int {
if coder.HTTP == 0 {
return http.StatusInternalServerError
}
return coder.HTTP
}
// nolint: unparam
func register(code int, httpStatus int, message string, refs ...string) {
found, _ := gubrak.Includes([]int{200, 400, 401, 403, 404, 500}, httpStatus)
if !found {
panic("http code not in `200, 400, 401, 403, 404, 500`")
}
var reference string
if len(refs) > 0 {
reference = refs[0]
}
coder := &ErrCode{
C: code,
HTTP: httpStatus,
Ext: message,
Ref: reference,
}
errors.MustRegister(coder)
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。