code

package
v2.37.2+incompatible Latest Latest
Warning

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

Go to latest
Published: Jul 26, 2023 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.StatusOK},
	SystemNotInstalled: {"SystemNotInstalled", http.StatusOK},

	OperationProcessing: {"OperationProcessing", http.StatusOK},
	FrequencyTooFast:    {"FrequencyTooFast", http.StatusOK},
	RequestFailure:      {"RequestFailure", http.StatusOK},
	RequestTimeout:      {"RequestTimeout", http.StatusOK},
	AbnormalResponse:    {"AbnormalResponse", http.StatusOK},
	OperationTimeout:    {"OperationTimeout", http.StatusOK},
	Unsupported:         {"Unsupported", http.StatusOK},
	RepeatOperation:     {"RepeatOperation", http.StatusOK},

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

	DataSizeTooBig:      {"DataSizeTooBig", http.StatusOK},
	DataAlreadyExists:   {"DataAlreadyExists", http.StatusOK},
	DataFormatIncorrect: {"DataFormatIncorrect", http.StatusOK},
	DataStatusIncorrect: {"DataStatusIncorrect", http.StatusOK},
	DataHasExpired:      {"DataHasExpired", http.StatusOK},
	DataProcessing:      {"DataProcessing", http.StatusOK},
	DataUnavailable:     {"DataUnavailable", http.StatusOK},
	InvalidType:         {"InvalidType", http.StatusOK},
	InvalidSignature:    {"InvalidSignature", http.StatusOK},
	InvalidParameter:    {"InvalidParameter", http.StatusOK},
	DataNotFound:        {"DataNotFound", http.StatusOK},

	CaptchaCodeRequired: {"CaptchaCodeRequired", http.StatusOK},
	CaptchaIdMissing:    {"CaptchaIdMissing", http.StatusOK},
	CaptchaError:        {"CaptchaError", http.StatusOK},
	BalanceNoEnough:     {"BalanceNoEnough", http.StatusOK},
	UserDisabled:        {"UserDisabled", http.StatusOK},
	UserNotFound:        {"UserNotFound", http.StatusOK},
	NonPrivileged:       {"NonPrivileged", http.StatusOK},
	Unauthenticated:     {"Unauthenticated", http.StatusOK},

	Failure: {"Failure", http.StatusOK},
	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