apperror

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Jun 18, 2026 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Code

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

Code 应用错误码

func NewCode

func NewCode(value int, name, defaultMsg string) Code

NewCode 创建错误码

func (Code) DefaultMsg added in v1.3.0

func (c Code) DefaultMsg() string

DefaultMsg 返回默认消息

func (Code) String

func (c Code) String() string

String 返回错误码名称

func (Code) Value

func (c Code) Value() int

Value 返回错误码数值

type Error

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

Error 应用错误,唯一的核心错误类型

func New

func New(code Code, opts ...Option) *Error

New 创建应用错误

func Wrap

func Wrap(code Code, cause error, opts ...Option) *Error

Wrap 快捷包装已有错误

func (*Error) Cause

func (e *Error) Cause() error

Cause 返回内部原始错误

func (*Error) Code

func (e *Error) Code() Code

Code 返回错误码

func (*Error) Error

func (e *Error) Error() string

Error 实现 error 接口,返回错误消息

func (*Error) Format

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

Format 实现 fmt.Formatter,支持 %+v 打印调试信息

func (*Error) Is

func (e *Error) Is(target error) bool

Is 实现 errors.Is 协议,按 Code 匹配

func (*Error) Unwrap

func (e *Error) Unwrap() error

Unwrap 实现 errors.Unwrap 协议,返回内部原因

type Option

type Option func(*Error)

Option 错误构建选项

func WithCause

func WithCause(err error) Option

WithCause 设置内部原始错误

func WithMsg

func WithMsg(msg string) Option

WithMsg 覆盖默认消息

func WithMsgf added in v1.3.0

func WithMsgf(format string, args ...any) Option

WithMsgf 格式化覆盖默认消息

Jump to

Keyboard shortcuts

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