Help us shape the future of Go! Take the 2026 Go Developer Survey

codes

package
v2.3.2 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2025 License: MIT Imports: 4 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	OK               = NewCode(0, "ok")
	Canceled         = NewCode(1, "canceled")
	Unknown          = NewCode(2, "unknown")
	InvalidArgument  = NewCode(3, "invalid argument")
	DeadlineExceeded = NewCode(4, "deadline exceeded")
	NotFound         = NewCode(5, "not found")
	InternalError    = NewCode(6, "internal error")
	Unauthorized     = NewCode(7, "unauthorized")
	IllegalInvoke    = NewCode(8, "illegal invoke")
	IllegalRequest   = NewCode(9, "illegal request")
	TooManyRequests  = NewCode(10, "too many requests")
)

Functions

This section is empty.

Types

type Code

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

func Convert

func Convert(err error) *Code

Convert 将错误信息转换为错误码

func NewCode

func NewCode(code int, message ...string) *Code

NewCode 新建一个错误码

func (*Code) Code

func (c *Code) Code() int

Code 返回错误码

func (*Code) Err

func (c *Code) Err() error

Err 转错误消息

func (*Code) Format

func (c *Code) Format(s fmt.State, verb rune)

Format 格式化输出 %s : 打印错误码和错误消息 %v : 打印错误码、错误消息、错误详情

func (*Code) Message

func (c *Code) Message() string

Message 返回错误码消息

func (*Code) String

func (c *Code) String() string

String 格式化错误码

func (*Code) WithCode

func (c *Code) WithCode(code int) *Code

WithCode 替换新的错误码

func (*Code) WithMessage

func (c *Code) WithMessage(message string) *Code

WithMessage 替换新的错误码消息

type Error

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

func (*Error) Error

func (e *Error) Error() string

Error error interface implementation

Jump to

Keyboard shortcuts

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