1
0
mirror of https://github.com/charlienet/go-mixed.git synced 2025-07-18 00:22:41 +08:00
This commit is contained in:
2023-08-25 15:31:00 +08:00
parent 04aecd4abc
commit b0a97978d8
58 changed files with 1330 additions and 476 deletions

View File

@ -12,6 +12,17 @@ const (
defaultErrorCode = "999999"
)
type Error interface {
Wraped() []error
Code() string
error
private()
}
var _ Error = &CodeError{}
type CodeError struct {
cause error // 原始错误信息
code string // 错误码
@ -70,6 +81,10 @@ func (e *CodeError) WithCause(err error) *CodeError {
return new(err, e.code, e.message)
}
func (e *CodeError) Wraped() []error {
return []error{}
}
func (e *CodeError) Format(s fmt.State, verb rune) {
switch verb {
case 'v':
@ -86,6 +101,8 @@ func (e *CodeError) Format(s fmt.State, verb rune) {
}
}
func (*CodeError) private() {}
func new(err error, code string, args ...any) *CodeError {
return &CodeError{
code: code,
@ -102,7 +119,7 @@ func newf(err error, code string, format string, args ...any) *CodeError {
}
}
func Error(code string, args ...any) *CodeError {
func ErrorWithCode(code string, args ...any) *CodeError {
return new(nil, code, args...)
}