errors

package
v1.3.2 Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2021 License: Apache-2.0 Imports: 11 Imported by: 1

Documentation

Overview

系统错误

Index

Constants

View Source
const (
	CodeOk        int32 = 0
	CodeUniversal       = 1
	CodeUnknown         = 2
	CodeInvalid         = 3
	CodeExists          = 4

	CodeStarted  = 90
	CodeFinished = 91
	CodeOther    = 99
)

App System Error Code (1 ~ 99)

View Source
const (
	CodeUnauthorized = 401
	CodeForbidden    = 403
	CodeNotFound     = 404
	CodeTimeout      = 408

	CodeServerError        = 500
	CodeServiceUnavailable = 503
)

HTTP Status Code (100 ~ 600)

Variables

View Source
var (
	Lang = map[string]*Status{
		"en-us": NewStatus("en-us"),
		"zh-cn": NewStatus("zh-cn"),
	}
)

Functions

func AddStatus

func AddStatus(status *Status)

注册语言环境

func AddStatusText

func AddStatusText(lang string, code int32, text string)

注册语言环境信息

func Cause added in v1.3.0

func Cause(err error) error

Cause returns the underlying cause of the error, if possible. An error value has a cause if it implements the following interface:

type causer interface {
       Cause() error
}

If the error does not implement Cause, the original error will be returned. If the error is nil, nil will be returned without further investigation.

func GetText

func GetText(lang string, code int32) string

获取语言环境信息

func Is

func Is(a, b error) bool

Is 比较两个错误

func IsCode

func IsCode(err error, code int32) bool

IsCode 检查错误码

func IsStack added in v1.3.0

func IsStack() bool

func MicroError added in v1.3.0

func MicroError(id string, err error) *errors.Error

func SetDefaultLang added in v1.3.0

func SetDefaultLang(lang string)

设置默认语言环境

func StatusText

func StatusText(code int32) string

获取默认语言环境

func Wrap

func Wrap(err error, args ...interface{}) error

WithStack annotates err with a stack trace at the point WithStack was called. If err is nil, WithStack returns nil.

Types

type Error added in v1.3.0

type Error struct {
	Code   int32  `json:"code"`
	Status string `json:"status"`
	Detail string `json:"detail"`
	// contains filtered or unexported fields
}

func Exists added in v1.3.0

func Exists(args ...interface{}) *Error

已存在

func Finished added in v1.3.0

func Finished(args ...interface{}) *Error

已结束

func Forbidden added in v1.3.0

func Forbidden(args ...interface{}) *Error

拒绝访问

func Invalid added in v1.3.0

func Invalid(args ...interface{}) *Error

无效

func New

func New(code int32, a ...interface{}) *Error

New returns an error with the supplied message. New also records the stack trace at the point it was called.

func NotFound added in v1.3.0

func NotFound(args ...interface{}) *Error

不存在

func Other added in v1.3.0

func Other(args ...interface{}) *Error

其它错误

func Parse

func Parse(err error) *Error

func Server added in v1.3.0

func Server(args ...interface{}) *Error

服务器错误

func Started added in v1.3.0

func Started(args ...interface{}) *Error

已开始

func Timeout added in v1.3.0

func Timeout(args ...interface{}) *Error

请求超时

func Unauthorized added in v1.3.0

func Unauthorized(args ...interface{}) *Error

未授权

func Unavailable added in v1.3.0

func Unavailable(args ...interface{}) *Error

不可用

func Universal added in v1.3.0

func Universal(args ...interface{}) *Error

通用错误

func Unknown added in v1.3.0

func Unknown(args ...interface{}) *Error

未知错误

func (*Error) Error added in v1.3.0

func (e *Error) Error() string

func (*Error) Format added in v1.3.0

func (e *Error) Format(s fmt.State, verb rune)

func (Error) StackTrace added in v1.3.0

func (s Error) StackTrace() StackTrace

type Frame added in v1.3.0

type Frame uintptr

Frame represents a program counter inside a stack frame. For historical reasons if Frame is interpreted as a uintptr its value represents the program counter + 1.

func (Frame) Format added in v1.3.0

func (f Frame) Format(s fmt.State, verb rune)

Format formats the frame according to the fmt.Formatter interface.

%s    source file
%d    source line
%n    function name
%v    equivalent to %s:%d

Format accepts flags that alter the printing of some verbs, as follows:

%+s   function name and path of source file relative to the compile time
      GOPATH separated by \n\t (<funcname>\n\t<path>)
%+v   equivalent to %+s:%d

func (Frame) MarshalText added in v1.3.0

func (f Frame) MarshalText() ([]byte, error)

MarshalText formats a stacktrace Frame as a text string. The output is the same as that of fmt.Sprintf("%+v", f), but without newlines or tabs.

type StackTrace added in v1.3.0

type StackTrace []Frame

StackTrace is stack of Frames from innermost (newest) to outermost (oldest).

func (StackTrace) Format added in v1.3.0

func (st StackTrace) Format(s fmt.State, verb rune)

Format formats the stack of Frames according to the fmt.Formatter interface.

%s	lists source files for each Frame in the stack
%v	lists the source file and line number for each Frame in the stack

Format accepts flags that alter the printing of some verbs, as follows:

%+v   Prints filename, function, and line number for each Frame in the stack.

type Status

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

语言包

func GetStatus

func GetStatus(lang string) *Status

注册语言环境

func NewStatus

func NewStatus(lang string) *Status

func (*Status) Add

func (s *Status) Add(code int32, text string)

func (*Status) Lang

func (s *Status) Lang() string

func (*Status) Status

func (s *Status) Status() map[int32]string

func (*Status) Text

func (s *Status) Text(code int32) string

Jump to

Keyboard shortcuts

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