@@ -0,0 +1,31 @@
|
||||
package stderr
|
||||
|
||||
import "fmt"
|
||||
|
||||
// CustomErr 代替/common/error中的定义,逐渐在代码中弃掉(common/error模块)
|
||||
type CustomErr struct {
|
||||
Code Code `json:"code"`
|
||||
Msg string `json:"msg"`
|
||||
Tips string `json:"tips"`
|
||||
}
|
||||
|
||||
// NewCustomErr an error
|
||||
func NewCustomErr(code Code, Msg string, tips ...string) *CustomErr {
|
||||
res := &CustomErr{
|
||||
Code: code,
|
||||
Msg: Msg,
|
||||
Tips: Msg,
|
||||
}
|
||||
if len(tips) > 0 {
|
||||
res.Tips = tips[0]
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
// Error 返回字符串
|
||||
func (s *CustomErr) Error() string {
|
||||
if s == nil {
|
||||
return ""
|
||||
}
|
||||
return fmt.Sprintf("code = %d, msg = %s ,tips = %v", s.Code, s.Msg, s.Tips)
|
||||
}
|
||||
Reference in New Issue
Block a user