Documentation
¶
Overview ¶
系统错误
Index ¶
- Constants
- Variables
- func AddStatus(status *Status)
- func AddStatusText(lang string, code int32, text string)
- func Cause(err error) error
- func GetText(lang string, code int32) string
- func Is(a, b error) bool
- func IsCode(err error, code int32) bool
- func IsStack() bool
- func MicroError(id string, err error) *errors.Error
- func SetDefaultLang(lang string)
- func StatusText(code int32) string
- func Wrap(err error, args ...interface{}) error
- type Error
- func Exists(args ...interface{}) *Error
- func Finished(args ...interface{}) *Error
- func Forbidden(args ...interface{}) *Error
- func Invalid(args ...interface{}) *Error
- func New(code int32, a ...interface{}) *Error
- func NotFound(args ...interface{}) *Error
- func Other(args ...interface{}) *Error
- func Parse(err error) *Error
- func Server(args ...interface{}) *Error
- func Started(args ...interface{}) *Error
- func Timeout(args ...interface{}) *Error
- func Unauthorized(args ...interface{}) *Error
- func Unavailable(args ...interface{}) *Error
- func Universal(args ...interface{}) *Error
- func Unknown(args ...interface{}) *Error
- type Frame
- type StackTrace
- type Status
Constants ¶
const ( CodeOk int32 = 0 CodeUniversal = 1 CodeUnknown = 2 CodeInvalid = 3 CodeExists = 4 CodeStarted = 90 CodeFinished = 91 CodeOther = 99 )
App System Error Code (1 ~ 99)
const ( CodeForbidden = 403 CodeNotFound = 404 CodeTimeout = 408 CodeServerError = 500 )
HTTP Status Code (100 ~ 600)
Variables ¶
var ( Lang = map[string]*Status{ "en-us": NewStatus("en-us"), "zh-cn": NewStatus("zh-cn"), } )
Functions ¶
func Cause ¶ added in v1.3.0
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.
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 New ¶
New returns an error with the supplied message. New also records the stack trace at the point it was called.
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
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
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.