kerror

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2022 License: MIT Imports: 2 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	OK                  = &KError{Code: 0, Message: "OK"}
	InternalServerError = &KError{Code: 10001, Message: "Internal server error."}
	ErrBind             = &KError{Code: 10002, Message: "Error occurred while binding the request body to the struct."}
)

1 00 01 服务级别 模块 具体错误

Functions

func DecodeErr

func DecodeErr(err error) (int, string)

DecodeErr 解码错误, 获取 Code 和 Message

func Wrap added in v0.0.8

func Wrap(message string, err error) error

Wrap is a simple wrapper around Errorf that is doing error wrapping. You can read how that works in https://godoc.org/golang.org/x/xerrors#Errorf but its API is very implicit which is a reason for this wrapper. There is also a discussion (https://github.com/golang/go/issues/29934) where many comments make arguments for such wrapper so hopefully it will be added in the standard lib later.

func WrapF added in v0.1.3

func WrapF(err error, message string, a ...interface{}) error

WrapF is a simple wrapper around Errorf that is doing error wrapping WrapF allows you to send a format and args instead of just a message.

Types

type Err

type Err struct {
	Code     int    // 错误码
	Message  string // 展示给用户看的
	ErrInner error  // 保存内部错误信息
}

Err 定义错误

func New

func New(errno *KError, err error) *Err

New 使用 错误码 和 error 创建新的 错误

func (*Err) Error

func (err *Err) Error() string

type KError

type KError struct {
	Code    int
	Message string
}

KError 定义错误码

func (KError) Error

func (err KError) Error() string

Jump to

Keyboard shortcuts

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