初始化项目

This commit is contained in:
lianghuanjie
2024-12-05 20:51:35 +08:00
commit e2ba6924b8
30 changed files with 1560 additions and 0 deletions

View File

@@ -0,0 +1,40 @@
package errs
import (
"fmt"
"github.com/spf13/cast"
)
type err struct {
code int
reason Reason
msg string
}
func New(code int, reason Reason, message any) error {
return err{
code: code,
reason: reason,
msg: cast.ToString(message),
}
}
// Error error
func (e err) Error() string {
return fmt.Sprintf("code=%d msg=%s", e.code, e.msg)
}
// Code return code
func (e err) Code() int {
return e.code
}
// Reason return reason
func (e err) Reason() Reason {
return e.reason
}
// Message return message
func (e err) Message() string {
return e.msg
}