code

package
v1.12.12 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2024 License: Apache-2.0 Imports: 1 Imported by: 156

Documentation

Index

Constants

This section is empty.

Variables

View Source
var CodeDict = CodeMap{

	SystemUnauthorized: {"SystemUnauthorized", http.StatusServiceUnavailable},
	SystemNotInstalled: {"SystemNotInstalled", http.StatusServiceUnavailable},

	OperationProcessing: {"OperationProcessing", http.StatusProcessing},
	FrequencyTooFast:    {"FrequencyTooFast", http.StatusTooManyRequests},
	RequestFailure:      {"RequestFailure", http.StatusBadRequest},
	RequestTimeout:      {"RequestTimeout", http.StatusRequestTimeout},
	AbnormalResponse:    {"AbnormalResponse", http.StatusInternalServerError},
	OperationTimeout:    {"OperationTimeout", http.StatusRequestTimeout},
	Unsupported:         {"Unsupported", http.StatusNotImplemented},
	RepeatOperation:     {"RepeatOperation", http.StatusBadRequest},

	InvalidAppID: {"InvalidAppID", http.StatusBadRequest},
	InvalidToken: {"InvalidToken", http.StatusBadRequest},

	DataSizeTooBig:      {"DataSizeTooBig", http.StatusRequestEntityTooLarge},
	DataAlreadyExists:   {"DataAlreadyExists", http.StatusBadRequest},
	DataFormatIncorrect: {"DataFormatIncorrect", http.StatusBadRequest},
	DataStatusIncorrect: {"DataStatusIncorrect", http.StatusBadRequest},
	DataHasExpired:      {"DataHasExpired", http.StatusBadRequest},
	DataProcessing:      {"DataProcessing", http.StatusProcessing},
	DataUnavailable:     {"DataUnavailable", http.StatusBadRequest},
	InvalidType:         {"InvalidType", http.StatusBadRequest},
	InvalidSignature:    {"InvalidSignature", http.StatusBadRequest},
	InvalidParameter:    {"InvalidParameter", http.StatusBadRequest},
	DataNotFound:        {"DataNotFound", http.StatusNotFound},

	CaptchaCodeRequired: {"CaptchaCodeRequired", http.StatusBadRequest},
	CaptchaIdMissing:    {"CaptchaIdMissing", http.StatusBadRequest},
	CaptchaError:        {"CaptchaError", http.StatusBadRequest},
	BalanceNoEnough:     {"BalanceNoEnough", http.StatusPreconditionFailed},
	UserDisabled:        {"UserDisabled", http.StatusBadRequest},
	UserNotFound:        {"UserNotFound", http.StatusBadRequest},
	NonPrivileged:       {"NonPrivileged", http.StatusForbidden},
	Unauthenticated:     {"Unauthenticated", http.StatusUnauthorized},

	Failure: {"Failure", http.StatusInternalServerError},
	Success: {"Success", http.StatusOK},
}

CodeDict 状态码字典

Functions

func Register

func Register(code Code, text string, httpCodes ...int)

Types

type Code

type Code int
const (
	SystemUnauthorized Code = -301 // 系统未获得授权
	SystemNotInstalled Code = -300 // 系统未安装

	FrequencyTooFast    Code = -207 //操作频率太快
	OperationProcessing Code = -206 //操作处理中
	RequestFailure      Code = -205 //提交失败
	RequestTimeout      Code = -204 //提交超时
	AbnormalResponse    Code = -203 //响应异常
	OperationTimeout    Code = -202 //操作超时
	Unsupported         Code = -201 //不支持的操作
	RepeatOperation     Code = -200 //重复操作

	InvalidToken Code = -151 //令牌错误
	InvalidAppID Code = -150 //AppID不正确

	DataSizeTooBig      Code = -110 //数据尺寸太大
	DataAlreadyExists   Code = -109 //数据已经存在
	DataFormatIncorrect Code = -108 //数据格式不正确
	DataStatusIncorrect Code = -107 //数据状态不正确
	DataProcessing      Code = -106 //数据未处理中状态
	DataUnavailable     Code = -105 //尚未启用
	DataHasExpired      Code = -104 //数据已经过期
	InvalidType         Code = -103 //类型不正确
	InvalidSignature    Code = -102 //无效的签名
	InvalidParameter    Code = -101 //无效的参数
	DataNotFound        Code = -100 //数据未找到

	CaptchaCodeRequired Code = -11 // captcha code 不能为空
	CaptchaIdMissing    Code = -10 // 缺少captchaId
	CaptchaError        Code = -9  //验证码错误
	BalanceNoEnough     Code = -5  //余额不足
	UserDisabled        Code = -4  //用户被禁用
	UserNotFound        Code = -3  //用户未找到
	NonPrivileged       Code = -2  //无权限
	Unauthenticated     Code = -1  //未登录

	Failure Code = 0 //操作失败
	Success Code = 1 //操作成功
)

func (Code) Between

func (c Code) Between(start Code, end Code) bool

Between 是否属于某个区间的状态码

func (Code) Fail

func (c Code) Fail() bool

Fail 是否是失败状态

func (Code) HTTPCode

func (c Code) HTTPCode() int

HTTPCode 返回HTTP状态码

func (Code) In

func (c Code) In(expected ...Code) bool

In 是否属于期望状态列表中的任一状态

func (Code) Int

func (c Code) Int() int

Int 返回int类型的自定义状态码

func (Code) Is

func (c Code) Is(expected Code) bool

Is 是否是期望状态

func (Code) Ok

func (c Code) Ok() bool

Ok 是否是成功状态

func (Code) String

func (c Code) String() string

type CodeMap

type CodeMap map[Code]TextHTTPCode

func (CodeMap) Get

func (s CodeMap) Get(code Code) TextHTTPCode

func (CodeMap) GetByInt

func (s CodeMap) GetByInt(code int) TextHTTPCode

func (CodeMap) Set

func (s CodeMap) Set(code Code, text string, httpCodes ...int) CodeMap

func (CodeMap) SetHTTPCodeToExists

func (s CodeMap) SetHTTPCodeToExists(code Code, httpCode int) CodeMap

func (CodeMap) SetToExists

func (s CodeMap) SetToExists(code Code, text string, httpCodes ...int) CodeMap

type TextHTTPCode

type TextHTTPCode struct {
	Text     string
	HTTPCode int
}

func Get

func Get(code Code) TextHTTPCode

Jump to

Keyboard shortcuts

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