err.go 512 B

123456789101112131415161718192021
  1. package ierr
  2. import "fmt"
  3. type IError struct {
  4. Code Code `json:"code"`
  5. Msg string `json:"msg"` //跟code一致的
  6. MoreInfo string `json:"more_info"`
  7. }
  8. func NewIError(code Code, moreInfo string) *IError {
  9. return &IError{Code: code, MoreInfo: moreInfo}
  10. }
  11. func NewIErrorf(code Code, format string, args ...interface{}) *IError {
  12. return &IError{Code: code, MoreInfo: fmt.Sprintf(format, args...)}
  13. }
  14. func (e *IError) Error() string {
  15. return fmt.Sprintf("code(%d),err(%s)", e.Code, e.MoreInfo)
  16. }