errno

package
v0.0.0-...-25e9490 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 22, 2025 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// SuccessCode For microservices
	SuccessCode = 10000
	SuccessMsg  = "ok"
)
View Source
const (
	ParamVerifyErrorCode   = 20000 + iota // 参数校验失败
	ParamMissingErrorCode                 // 参数缺失
	ParamMissingHeaderCode                // 请求头缺失
	ParamInvalidHeaderCode                // 请求头无效
)

200xx: 参数错误,Param 打头

View Source
const (
	AuthInvalidCode             = 30000 + iota // 鉴权失败
	AuthAccessExpiredCode                      // 访问令牌过期
	AuthRefreshExpiredCode                     // 刷新令牌过期
	AuthNoTokenCode                            // 没有 token
	AuthNoOperatePermissionCode                // 没有操作权限
	AuthMissingTokenCode                       // 缺少 token
)

300xx: 鉴权错误,Auth 打头

View Source
const (
	InternalServiceErrorCode  = 50000 + iota // 内部服务错误
	InternalDatabaseErrorCode                // 数据库错误
	InternalRedisErrorCode                   // Redis错误
	InternalNetworkErrorCode                 // 网络错误
	InternalESErrorCode                      // ES错误
	InternalKafkaErrorCode                   // kafka 错误
	OSOperateErrorCode
	IOOperateErrorCode
)

500xx: 内部错误,Internal 打头 服务级别的错误, 发生的时候说明我们程序自身出了问题 比如数据库断联, 编码错误等. 需要我们人为的去维护

View Source
const (
	// User
	ServiceWrongPassword = 1000 + iota
	ServiceUserExist
	ServiceUserNotExist

	// order
	ServiceOrderNotFound
	ServiceSpuNotExist
	ServiceImgNotExist
	PaymentOrderNotExist
	UserNotExist
)

业务强相关, 范围是 1000-9999

View Source
const (
	ServiceError = 10001
)
View Source
const (
	UpYunFileErrorCode = 60000 + iota
)

Variables

View Source
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

type ErrNo struct {
	ErrorCode int64
	ErrorMsg  string
	// contains filtered or unexported fields
}

func ConvertErr

func ConvertErr(err error) ErrNo

ConvertErr convert error to ErrNo in Default user ServiceErrorCode

func Errorf

func Errorf(code int64, template string, args ...interface{}) ErrNo

func NewErrNo

func NewErrNo(code int64, msg string) ErrNo

func NewErrNoWithStack

func NewErrNoWithStack(code int64, msg string) ErrNo

func (ErrNo) Error

func (e ErrNo) Error() string

func (ErrNo) Format

func (e ErrNo) Format(st fmt.State, verb rune)

func (ErrNo) StackTrace

func (e ErrNo) StackTrace() any

func (ErrNo) WithError

func (e ErrNo) WithError(err error) ErrNo

WithError will add error msg after Message

func (ErrNo) WithMessage

func (e ErrNo) WithMessage(msg string) ErrNo

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

func (f Frame) Format(s fmt.State, verb rune)

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

func (f Frame) MarshalText() ([]byte, error)

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL