errcode

package
v1.3.2 Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2022 License: MIT Imports: 2 Imported by: 0

README

errcode

错误码通常包括系统级错误码和服务级错误码,一共5位十进制数字组成,例如20101

2 01 01
2表示服务级错误(1为系统级错误) 服务模块代码 具体错误代码
  • 错误级别占一位数:1表示系统级错误,2表示服务级错误,通常是由用户非法操作引起的。
  • 服务模块占两位数:一个大型系统的服务模块通常不超过两位数,如果超过,说明这个系统该拆分了。
  • 错误码占两位数:防止一个模块定制过多的错误码,后期不好维护。

使用示例

    // 定义错误码
    ErrLogin = errcode.NewError(20101, "用户名或密码错误")

    // 请求返回
    render.Error(c, errcode.LoginErr)

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Success             = NewError(0, "ok")
	InvalidParams       = NewError(10001, "参数错误")
	Unauthorized        = NewError(10002, "认证错误")
	InternalServerError = NewError(10003, "服务内部错误")
	NotFound            = NewError(10004, "资源不存在")
	AlreadyExists       = NewError(10005, "资源已存在")
	Timeout             = NewError(10006, "超时")
	TooManyRequests     = NewError(10007, "请求过多")
	Forbidden           = NewError(10008, "拒绝访问")
	LimitExceed         = NewError(10009, "访问限制")
)

系统级别错误码,无Err前缀

Functions

This section is empty.

Types

type Error

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

Error 错误

func NewError

func NewError(code int, msg string) *Error

NewError 创建新错误信息

func (*Error) Code

func (e *Error) Code() int

Code 错误码

func (*Error) Details

func (e *Error) Details() []string

Details 错误详情

func (*Error) Error

func (e *Error) Error() string

String 打印错误

func (*Error) Msg

func (e *Error) Msg() string

Msg 错误信息

func (*Error) Msgf

func (e *Error) Msgf(args []interface{}) string

Msgf 附加信息

func (*Error) StatusCode

func (e *Error) StatusCode() int

StatusCode 对应http错误码

func (*Error) WithDetails

func (e *Error) WithDetails(details ...string) *Error

WithDetails 携带附加错误详情

Jump to

Keyboard shortcuts

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