Files
go-pkg/errors/error.go
pyihe 07a4a781a6 feature(pkg): modify
add func, remove rediss
2022-05-16 10:18:11 +08:00

30 lines
379 B
Go

package errors
import "fmt"
type Error struct {
err string
code int32
}
func New(err string, codes ...int32) error {
e := &Error{
err: err,
}
if len(codes) > 0 {
e.code = codes[0]
}
return e
}
func (e *Error) Error() (err string) {
if e.code == 0 {
return e.err
}
return fmt.Sprintf("%d-%s", e.code, e.err)
}
func (e *Error) Code() int32 {
return e.code
}