正在显示
2 个修改的文件
包含
41 行增加
和
0 行删除
common/error.go
0 → 100644
| 1 | +package common | ||
| 2 | + | ||
| 3 | +import "fmt" | ||
| 4 | + | ||
| 5 | +type Error struct { | ||
| 6 | + Code int | ||
| 7 | + err error | ||
| 8 | +} | ||
| 9 | + | ||
| 10 | +func (e Error)Error()string{ | ||
| 11 | + if e.err==nil{ | ||
| 12 | + return "" | ||
| 13 | + } | ||
| 14 | + return e.err.Error() | ||
| 15 | +} | ||
| 16 | + | ||
| 17 | +func NewError(code int,e error)Error{ | ||
| 18 | + return Error{ | ||
| 19 | + Code:code, | ||
| 20 | + err:e, | ||
| 21 | + } | ||
| 22 | +} | ||
| 23 | + | ||
| 24 | +func NewErrorWithMsg(code int,msg string)Error{ | ||
| 25 | + return NewError(code,fmt.Errorf(msg)) | ||
| 26 | +} |
common/error_test.go
0 → 100644
-
请 注册 或 登录 后发表评论