12345678910111213141516171819202122232425262728293031323334353637 |
- package errors
- import "fmt"
- type TError struct {
- code int
- msg string
- }
- func (e TError) Error() string {
- return fmt.Sprintf("code:%d,msg:%v", e.code, e.msg)
- }
- func NewTError(code int, msg string) error {
- return TError{
- code: code,
- msg: msg,
- }
- }
- func GetCode(err error) int {
- if e, ok := err.(TError); ok {
- return e.code
- }
- return -1
- }
- func GetMsg(err error) string {
- if e, ok := err.(TError); ok {
- return e.msg
- }
- return ""
- }
|