ecode

package
v0.1.26 Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2020 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	OK = add(0) // 正确

	NotModified        = add(-304) // 木有改动
	TemporaryRedirect  = add(-307) // 撞车跳转
	RequestErr         = add(-400) // 请求错误
	Unauthorized       = add(-401) // 未认证
	AccessDenied       = add(-403) // 访问权限不足
	NothingFound       = add(-404) // 啥都木有
	MethodNotAllowed   = add(-405) // 不支持该方法
	Conflict           = add(-409) // 冲突
	Canceled           = add(-498) // 客户端取消请求
	ServerErr          = add(-500) // 服务器错误
	ServiceUnavailable = add(-503) // 过载保护,服务暂不可用
	Deadline           = add(-504) // 服务调用超时
	LimitExceed        = add(-509) // 超出限制
)

All common ecode

View Source
var (
	// Code
	CodeNotFound = New(100000) // 验证码未找到
	CodeNotMatch = New(100001) // 验证码不匹配

	// Token
	TokenNotFound    = New(100010) // token未找到
	TokenNotMatch    = New(100011) // token不匹配
	TokenInvalid     = New(100012) // token不合法
	TokenDelErr      = New(100013) // token销毁失败
	TokenAppIDDelErr = New(100014) // 登录的appIDs销毁失败

	// AccessToken
	AccessTokenInvalid = New(100020) // access_token无效
	AccessTokenExpired = New(100021) // access_token过期

	// RefreshToken
	RefreshTokenInvalid = New(100030) // refresh_token无效
	RefreshTokenExpired = New(100031) // refresh_token过期

	// User
	UserNotFound = New(100100) // 用户未找到
	UserNotMatch = New(100101) // 用户不匹配
	UserNotLogin = New(100102) // 用户未登录
	UserHasLogin = New(100103) // 用户已登录
	UserIsBanned = New(100104) // 用户被关小黑屋

	// Picture
	PicTooBig   = New(100120) // 图片尺寸过大
	PicExtErr   = New(100201) // 图片格式错误
	PicNotFound = New(100202) // 图片不存在
	PicTooMuch  = New(100204) // 图片要素过多
	PicAbnormal = New(100205) // 图片违规

	// App
	AppNotFound = New(100110) // 用户未找到
	AppNotMatch = New(100111) // 用户不匹配
	AppIsBanned = New(100112) // 用户被关小黑屋

	// Illegal
	IllegalParam = New(200000) // 非法参数
	IllegalName  = New(200001) // 非法名称
	IllegalURL   = New(200002) // 非法URL
	IllegalDate  = New(200003) // 非法日期
	IllegalTime  = New(200004) // 非法时间
	IllegalGeo   = New(200005) // 非法地理位置
	IllegalTel   = New(200006) // 非法电话号码
	IllegalEmail = New(200007) // 非法邮箱格式
)

main ecode interval is [0,990000] [100000,100099] is about authentication [200000,200099] is about vertification [100100,199999] is used for all applications

Functions

func Equal

func Equal(a, b Codes) bool

Equal checks if a equals to b by code int

func EqualError

func EqualError(code Codes, err error) bool

EqualError checks if code equals to error

func Register

func Register(cm map[int]string)

Register register ecode message map

Types

type Code

type Code int

Code an int error spec

func Int

func Int(i int) Code

Int parses code int to error

func New

func New(e int) Code

New new an ecode.Codes by int value

func String

func String(e string) Code

String parses code string to error

func (Code) Code

func (e Code) Code() int

Code returns error code

func (Code) Details

func (e Code) Details() []interface{}

Details returns error details

func (Code) Error

func (e Code) Error() string

func (Code) Message

func (e Code) Message() string

Message returns error message

type Codes

type Codes interface {
	// sometimes Error return Code in string form
	// NOTE: don't use Error in monitor report even it also work for now
	Error() string
	// Code get error code.
	Code() int
	// Message get code message.
	Message() string
	//Detail get error detail,it may be nil.
	Details() []interface{}
}

Codes ecode error interface which has a code & message.

func Cause

func Cause(e error) Codes

Cause causes from error to ecode

Jump to

Keyboard shortcuts

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