ecode

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2019 License: MIT Imports: 7 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

Functions

func Equal

func Equal(a, b Codes) bool

Equal equal a and b by code int.

func EqualError

func EqualError(code Codes, err error) bool

EqualError equal error

func Register

func Register(cm map[int]string)

Register register ecode message map.

Types

type Code

type Code int

A Code is an int error code spec.

func Int

func Int(i int) Code

Int parse code int to error.

func New

func New(e int) Code

New new a ecode.Codes by int value. NOTE: ecode must unique in global, the New will check repeat and then panic.

func String

func String(e string) Code

String parse code string to error.

func (Code) Code

func (e Code) Code() int

Code return error code

func (Code) Details

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

Details return details.

func (Code) Equal

func (e Code) Equal(err error) bool

Equal for compatible. Deprecated: please use ecode.EqualError.

func (Code) Error

func (e Code) Error() string

func (Code) Message

func (e Code) Message() string

Message return 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 cause from error to ecode.

func FromProto

func FromProto(pbMsg proto.Message) Codes

FromProto new status from grpc detail

type Status

type Status struct {
	// contains filtered or unexported fields
}

Status statusError is an alias of a status proto implement ecode.Codes

func Error

func Error(code Code, message string) *Status

Error new status with code and message

func Errorf

func Errorf(code Code, format string, args ...interface{}) *Status

Errorf new status with code and message

func FromCode

func FromCode(code Code) *Status

FromCode create status from ecode

func (*Status) Code

func (s *Status) Code() int

Code return error code

func (*Status) Details

func (s *Status) Details() []interface{}

Details return error details

func (*Status) Equal

func (s *Status) Equal(err error) bool

Equal for compatible. Deprecated: please use ecode.EqualError.

func (*Status) Error

func (s *Status) Error() string

Error implement error

func (*Status) Message

func (s *Status) Message() string

Message return error message for developer

func (*Status) Proto

func (s *Status) Proto() *types.Status

Proto return origin protobuf message

func (*Status) WithDetails

func (s *Status) WithDetails(pbs ...proto.Message) (*Status, error)

WithDetails WithDetails

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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