ecode

package
v0.0.0-...-7429660 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2023 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	OK        = Int(0)
	ParamErr  = Int(499)
	ServerErr = Int(500)
)

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 Error

func Error(e int, msg string) Code

Error returns a ecode.Codes and register associated ecode message NOTE: Error codes and messages should be kept together. ecode must unique in global, the Error will check repeat and then panic.

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) Equal

func (e Code) Equal(err error) bool

Equal for compatible.

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 {
	// Error return Code in string form
	Error() string
	// Code get error code.
	Code() int
	// Message get code message.
	Message() string
	// Equal for compatible.
	Equal(error) bool
}

Codes ecode error interface which has a code & message.

func Cause

func Cause(e error) Codes

Cause cause from error to ecode.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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