Documentation ¶
Index ¶
Constants ¶
View Source
const ( // SERVER_COMMON_ERROR 通用服务编码 SERVER_COMMON_ERROR ErrCode = 10001 // REUQEST_PARAM_ERROR 请求参数错误 REUQEST_PARAM_ERROR ErrCode = 10002 // TOKEN_EXPIRE_ERROR Token过期 TOKEN_EXPIRE_ERROR ErrCode = 10003 // TOKEN_GENERATE_ERROR Token生成错误 TOKEN_GENERATE_ERROR ErrCode = 10004 // DB_ERROR 数据库错误 DB_ERROR ErrCode = 10005 // DB_QUERY_ERROR 数据库查询错误 DB_QUERY_ERROR ErrCode = 10006 // DB_LAST_INSERT_ID_ERROR 获取新书编号错误 DB_LAST_INSERT_ID_ERROR ErrCode = 10007 // DB_INSERT_ERROR 数据库创建错误 DB_INSERT_ERROR ErrCode = 10008 // DB_NOT_FOUND_ERROR 记录不存在 DB_NOT_FOUND_ERROR ErrCode = 10009 // DB_ALREADY_EXISTS_ERROR 记录已经存在 DB_ALREADY_EXISTS_ERROR ErrCode = 10010 // REQUEST_PARAM_REQUIRED_ERROR 删除必填 PARAM_REQUIRED_ERROR ErrCode = 10011 // DB_UPDATE_ERROR 更新错误 DB_UPDATE_ERROR ErrCode = 10012 // SQL_BUILD_ERROR sql构建错误 SQL_BUILD_ERROR = ErrCode(10013) // MARSHAL_ERROR json解析错误 MARSHAL_ERROR = ErrCode(10014) // TOKEN_PARSER_ERROR Token解析错误 TOKEN_PARSER_ERROR = ErrCode(10015) // CACHE_EXPIRE_ERROR 缓存过期 CACHE_EXPIRE_ERROR = ErrCode(10016) // CACHE_ERROR 缓存错误 CACHE_ERROR = ErrCode(10017) // LOGIN_TIMEOUT 登录超时 LOGIN_TIMEOUT = ErrCode(10018) // SIGNED_IN_ELSE_WHERE 在其他地方登录 SIGNED_IN_ELSE_WHERE = ErrCode(1009) // REQUIRE_TOKEN REQUIRED_TOKEN_ERROR = ErrCode(10020) // CAPTCHA_ERROR 验证码错误 CAPTCHA_ERROR = ErrCode(10021) // RECORD_DISABLED 禁用 RECORD_DISABLED = ErrCode(10022) // CACHE_NOT_FOUND 缓存不存在 CACHE_NOT_FOUND = ErrCode(10023) // DB_DELETE_EROR 数据库删除错误 DB_DELETE_EROR = ErrCode(10024) CACHE_DELETE_ERROR = ErrCode(10025) // 业务错误 BIZ_INFO = ErrCode(10000) OAUTH2_GRANT_CLIENT_ID_MISMATCH = ErrCode(10026) OAUTH2_GRANT_REDIRECT_URI_MISMATCH = ErrCode(10027) OAUTH2_GRANT_STATE_MISMATCH = ErrCode(10028) OAUTH2_CODE_NOT_EXISTS = ErrCode(10029) OAUTH2_CODE_EXPIRE = ErrCode(10030) // 未授权 UNAUTHORIZED = ErrCode(10031) PASSWORD_ERROR = ErrCode(10032) UNIMPLEMENTED = ErrCode(10034) // 未认证 UNAUTHENTICATION = ErrCode(10035) )
Variables ¶
View Source
var ( ServerCommonErr = func(err error, opts ...CodeErrOption) *CodeErr { return NewCodeErrWithMsg(SERVER_COMMON_ERROR, "系统错误", err, opts...) } RequestParamErr = func(msg string) *CodeErr { return NewCodeErrWithMsg(REUQEST_PARAM_ERROR, "参数错误", nil, WithMsgOption(msg)) } TokenExpireErr = func(msg string) *CodeErr { return NewCodeErrWithMsg(TOKEN_EXPIRE_ERROR, "Token过期", nil, WithMsgOption(msg)) } TokenGenerateErr = func(msg string) *CodeErr { return NewCodeErrWithMsg(TOKEN_GENERATE_ERROR, "Token生成错误", nil, WithMsgOption(msg)) } TokenParserErr = func(msg string) *CodeErr { return NewCodeErrWithMsg(TOKEN_PARSER_ERROR, "解析错误", nil, WithMsgOption(msg)) } DbErr = func(err error, opts ...CodeErrOption) *CodeErr { return NewCodeErrWithMsg(DB_ERROR, "数据库错误", err, opts...) } DbQueryErr = func(err error, msg string) *CodeErr { return NewCodeErrWithMsg(DB_QUERY_ERROR, "查询出错", err, WithMsgOption(msg)) } DbLastInsertIdErr = func(err error, msg string) *CodeErr { return NewCodeErrWithMsg(DB_LAST_INSERT_ID_ERROR, "查询失败", err, WithMsgOption(msg)) } DbInsertErr = func(err error, msg string) *CodeErr { return NewCodeErrWithMsg(DB_INSERT_ERROR, "创建失败", err, WithMsgOption(msg)) } DbNotFoundErr = func(msg string) *CodeErr { return NewCodeErrWithMsg(DB_NOT_FOUND_ERROR, "记录不存在", nil, WithMsgOption(msg)) } DbAlreadyExistsErr = func(msg string) *CodeErr { return NewCodeErrWithMsg(DB_ALREADY_EXISTS_ERROR, "记录已经存在", nil, WithMsgOption(msg)) } ParamRequiredErr = func(msg string) *CodeErr { return NewCodeErrWithMsg(PARAM_REQUIRED_ERROR, "缺少参数", nil, WithMsgOption(msg)) } DbUpdateErr = func(err error, msg string) *CodeErr { return NewCodeErrWithMsg(DB_UPDATE_ERROR, "更新失败", err, WithMsgOption(msg)) } SqlBuildErr = func(err error, msg string) *CodeErr { return NewCodeErrWithMsg(SQL_BUILD_ERROR, "sql构造错误", err, WithMsgOption(msg)) } MarshalErr = func(err error, msg string) *CodeErr { return NewCodeErrWithMsg(MARSHAL_ERROR, "解析错误", err, WithMsgOption(msg)) } CacheExpireErr = func(msg string) *CodeErr { return NewCodeErrWithMsg(CACHE_EXPIRE_ERROR, "缓存已过期", nil, WithMsgOption(msg)) } CacheErr = func(err error, msg string) *CodeErr { return NewCodeErrWithMsg(CACHE_ERROR, "缓存错误", err, WithMsgOption(msg)) } LoginTimeoutErr = func(err error) *CodeErr { return NewCodeErrWithMsg(LOGIN_TIMEOUT, "登录超时", err) } SignedInElsewhereErr = func() *CodeErr { return NewCodeErrWithMsg(SIGNED_IN_ELSE_WHERE, "在其他地方登录", nil) } RequiredTokenErr = func() *CodeErr { return NewCodeErrWithMsg(REQUIRED_TOKEN_ERROR, "未认证", nil) } CaptchaValidErr = func() *CodeErr { return NewCodeErrWithMsg(CAPTCHA_ERROR, "验证码验证失败", nil) } CacheNotFoundErr = func() *CodeErr { return NewCodeErrWithMsg(CACHE_NOT_FOUND, "不存在", nil) } DBDeleteErr = func(err error, msg string) *CodeErr { return NewCodeErrWithMsg(DB_DELETE_EROR, "删除错误", err, WithMsgOption(msg)) } UnImplementedErr = func() *CodeErr { return NewCodeErrWithMsg(UNIMPLEMENTED, "未实现", nil) } // 禁用 DisabledErr = func(msg string) *CodeErr { return NewCodeErrWithMsg(RECORD_DISABLED, "已禁用", nil, WithMsgOption(msg)) } // 未授权 UnAuothrizedErr = func(msg string) *CodeErr { return NewCodeErrWithMsg(UNAUTHORIZED, "未授权", nil, WithMsgOption(msg)) } // 未认证 UnAuthenticatedErr = func(msg string) *CodeErr { return NewCodeErrWithMsg(UNAUTHENTICATION, "未认证", nil, WithMsgOption(msg)) } // 业务错误,提示信息 BizError = func(msg string) *CodeErr { return NewCodeErrWithMsg(BIZ_INFO, msg, nil) } )
Functions ¶
func DefineErrMsg ¶
func DefineErrMsg(codeErr *CodeErr)
DefineErrMsg 定义错误Code ErrCode:10000001~10000005 为保留错误码 ErrCode 规则:业务编码(4位)+功能编码(4位)
Types ¶
type CodeErr ¶
type CodeErr struct {
// contains filtered or unexported fields
}
func NewCodeErrWithMsg ¶ added in v1.1.1
func NewCodeErrWithMsg(code ErrCode, msg string, inner error, opts ...CodeErrOption) *CodeErr
func NewCodeError ¶ added in v1.1.1
func NewCodeError(opts ...CodeErrOption) *CodeErr
func (*CodeErr) GetErrCode ¶
func (*CodeErr) InnerError ¶ added in v1.1.1
type CodeErrOption ¶ added in v1.1.1
type CodeErrOption func(*CodeErr)
func WithCodeOption ¶ added in v1.1.1
func WithCodeOption(code ErrCode) CodeErrOption
func WithErrorOption ¶ added in v1.1.1
func WithErrorOption(err error) CodeErrOption
func WithMsgOption ¶ added in v1.1.1
func WithMsgOption(msg string) CodeErrOption
Click to show internal directories.
Click to hide internal directories.