Documentation
¶
Index ¶
Constants ¶
const ( // SuccessCode For microservices SuccessCode = 10000 SuccessMsg = "ok" )
const ( ParamVerifyErrorCode = 20000 + iota // 参数校验失败 ParamMissingErrorCode // 参数缺失 ParamMissingHeaderCode // 请求头缺失 ParamInvalidHeaderCode // 请求头无效 )
200xx: 参数错误,Param 打头
const ( AuthInvalidCode = 30000 + iota // 鉴权失败 AuthAccessExpiredCode // 访问令牌过期 AuthRefreshExpiredCode // 刷新令牌过期 AuthNoTokenCode // 没有 token AuthNoOperatePermissionCode // 没有操作权限 AuthMissingTokenCode // 缺少 token )
300xx: 鉴权错误,Auth 打头
const ( InternalServiceErrorCode = 50000 + iota // 内部服务错误 InternalDatabaseErrorCode // 数据库错误 InternalRedisErrorCode // Redis错误 InternalNetworkErrorCode // 网络错误 InternalESErrorCode // ES错误 InternalKafkaErrorCode // kafka 错误 OSOperateErrorCode IOOperateErrorCode )
500xx: 内部错误,Internal 打头 服务级别的错误, 发生的时候说明我们程序自身出了问题 比如数据库断联, 编码错误等. 需要我们人为的去维护
const ( // User ServiceWrongPassword = 1000 + iota ServiceUserExist ServiceUserNotExist // order ServiceOrderNotFound ServiceSpuNotExist ServiceImgNotExist PaymentOrderNotExist UserNotExist )
业务强相关, 范围是 1000-9999
const (
ServiceError = 10001
)
const (
UpYunFileErrorCode = 60000 + iota
)
Variables ¶
var ( Success = NewErrNo(SuccessCode, "ok") ParamVerifyError = NewErrNo(ParamVerifyErrorCode, "parameter validation failed") ParamMissingError = NewErrNo(ParamMissingErrorCode, "missing parameter") AuthInvalid = NewErrNo(AuthInvalidCode, "authentication failure") AuthAccessExpired = NewErrNo(AuthAccessExpiredCode, "token expiration") AuthNoToken = NewErrNo(AuthNoTokenCode, "lack of token") AuthNoOperatePermission = NewErrNo(AuthNoOperatePermissionCode, "No permission to operate") InternalServiceError = NewErrNo(InternalServiceErrorCode, "internal server error") OSOperationError = NewErrNo(OSOperateErrorCode, "os operation failed") IOOperationError = NewErrNo(IOOperateErrorCode, "io operation failed") UpYunFileError = NewErrNo(UpYunFileErrorCode, "upyun operation failed") )
一些常用的的错误, 如果你懒得单独定义也可以直接使用
Functions ¶
This section is empty.
Types ¶
type ErrNo ¶
func ConvertErr ¶
ConvertErr convert error to ErrNo in Default user ServiceErrorCode
func NewErrNoWithStack ¶
func (ErrNo) StackTrace ¶
func (ErrNo) WithMessage ¶
WithMessage will replace default msg to new
type Frame ¶
type Frame uintptr
Frame represents a program counter inside a stack frame. For historical reasons if Frame is interpreted as a uintptr its value represents the program counter + 1.
func (Frame) Format ¶
Format formats the frame according to the fmt.Formatter interface.
%s source file %d source line %n function name %v equivalent to %s:%d
Format accepts flags that alter the printing of some verbs, as follows:
%+s function name and path of source file relative to the compile time GOPATH separated by \n\t (<funcname>\n\t<path>) %+v equivalent to %+s:%d
func (Frame) MarshalText ¶
MarshalText formats a stacktrace Frame as a text string. The output is the same as that of fmt.Sprintf("%+v", f), but without newlines or tabs.
type StackTrace ¶
type StackTrace []Frame
StackTrace is stack of Frames from innermost (newest) to outermost (oldest).
func (StackTrace) Format ¶
func (st StackTrace) Format(s fmt.State, verb rune)
Format formats the stack of Frames according to the fmt.Formatter interface.
%v lists the source file and line number for each Frame in the stack
Format accepts flags that alter the printing of some verbs, as follows:
%+v Prints filename, function, and line number for each Frame in the stack.