初始化项目
This commit is contained in:
40
internal/pkg/errs/error.go
Normal file
40
internal/pkg/errs/error.go
Normal 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
|
||||
}
|
||||
Reference in New Issue
Block a user