package cerror import ( "xiaoniaokuaiyan.com/xiaoniao/constants" ) import "fmt" type CError interface { error CError() string GetErrno() int } type customError struct { Errno constants.ErrorCode `json:"errno"` Errmsg string `json:"error"` } func (err *customError) Error() string { return err.Errmsg } func (err *customError) GetErrno() int { return int(err.Errno) } func (err *customError) CError() string { return fmt.Sprintf("%d:%s", err.Errno, err.Errmsg) } func New(errno constants.ErrorCode, msg string) *customError { return &customError{ Errno: errno, Errmsg: msg, } }