将common包改名为utils, 因为common太长了

This commit is contained in:
hahahrfool
2022-03-17 08:11:56 +08:00
parent 99afcc9eb8
commit c9cf683a58
18 changed files with 130 additions and 81 deletions

43
utils/error.go Normal file
View File

@@ -0,0 +1,43 @@
package utils
import "fmt"
type ErrInErr struct {
ErrDesc string
ErrDetail error
Data interface{}
}
func (e *ErrInErr) String() string {
if e.Data != nil {
if e.ErrDetail != nil {
return fmt.Sprintf("%s : %s, Data: %v", e.ErrDesc, e.ErrDetail.Error(), e.Data)
}
return fmt.Sprintf("%s , Data: %v", e.ErrDesc, e.Data)
}
return fmt.Sprintf("%s : %s", e.ErrDesc, e.ErrDetail.Error())
}
func (e *ErrInErr) Error() string {
return e.String()
}
func NewErr(desc string, e error) *ErrInErr {
return &ErrInErr{
ErrDesc: desc,
ErrDetail: e,
}
}
func NewDataErr(desc string, e error, data interface{}) *ErrInErr {
return &ErrInErr{
ErrDesc: desc,
ErrDetail: e,
Data: data,
}
}