package errorcode type BusinessErr struct { code int32 message string } func (e *BusinessErr) Error() string { return e.message } func (e *BusinessErr) Code() int32 { return e.code } func (e *BusinessErr) Is(target error) bool { _, ok := target.(*BusinessErr) return ok } // CustomErr 自定义错误 func NewBusinessErr(code int32, message string) *BusinessErr { return &BusinessErr{code: code, message: message} } func (e *BusinessErr) Wrap(err error) *BusinessErr { return NewBusinessErr(e.code, err.Error()) }