package errors import "fmt" type TError struct { code int msg string } // 实现 Error 接口 func (e TError) Error() string { return fmt.Sprintf("code:%d,msg:%v", e.code, e.msg) } // New new Error func NewTError(code int, msg string) error { return TError{ code: code, msg: msg, } } // GetCode 获取Code func GetCode(err error) int { if e, ok := err.(TError); ok { return e.code } return -1 } // GetMsg 获取Msg func GetMsg(err error) string { if e, ok := err.(TError); ok { return e.msg } return "" }