41 lines
577 B
Go
41 lines
577 B
Go
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
|
|
}
|