Golang常量错误帮助器

351 阅读1分钟

consterr

用于声明常量错误的小型类型助手:

// marker type.
// It a compile type meta for constant errors.
// We need it to distinguish two errors with equal values.
type errPackage struct{}

// Err is a package level error.
type Err = consterr.Err[errPackage]

const (
    ErrBadArg Err = "bad argument"
    ErrUnexpectedValue Err = "unexpected value"
)