实现 jwt、密码加密、casbin 的接入
This commit is contained in:
58
utility/ecode/ecode.go
Normal file
58
utility/ecode/ecode.go
Normal file
@ -0,0 +1,58 @@
|
||||
package ecode
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/gogf/gf/v2/errors/gcode"
|
||||
)
|
||||
|
||||
type Error struct {
|
||||
code int
|
||||
message string
|
||||
sub string
|
||||
params []interface{}
|
||||
}
|
||||
|
||||
func New(code int, message string) Error {
|
||||
return Error{
|
||||
code: code,
|
||||
message: message,
|
||||
}
|
||||
}
|
||||
|
||||
func (e Error) Params(params ...interface{}) Error {
|
||||
e.params = append(e.params, params...)
|
||||
return e
|
||||
}
|
||||
|
||||
func (e Error) Error() string {
|
||||
return e.Message()
|
||||
}
|
||||
|
||||
func (e Error) Sub(sub string) Error {
|
||||
e.sub = sub
|
||||
return e
|
||||
}
|
||||
|
||||
func (e Error) Message() string {
|
||||
if e.message != "" && len(e.params) > 0 {
|
||||
e.message = fmt.Sprintf(e.message, e.params...)
|
||||
}
|
||||
if e.sub != "" {
|
||||
if e.message != "" {
|
||||
if len(e.params) > 0 {
|
||||
e.message = fmt.Sprintf(e.message, e.params...)
|
||||
}
|
||||
return fmt.Sprintf("%s:%s", e.message, e.sub)
|
||||
}
|
||||
return e.sub
|
||||
}
|
||||
return e.message
|
||||
}
|
||||
|
||||
func (e Error) Code() gcode.Code {
|
||||
return gcode.New(e.code, e.Message(), "customer")
|
||||
}
|
||||
|
||||
func (e Error) Detail() interface{} {
|
||||
return "customer"
|
||||
}
|
||||
Reference in New Issue
Block a user