code_msg.go 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. package e
  2. type Rescode int64
  3. const (
  4. SUCCESS Rescode = 200 + iota
  5. ERROR
  6. )
  7. const (
  8. TokenIsInvalid Rescode = 1001 + iota
  9. TokenIsExpired
  10. DELETEFAIL
  11. UPDATEFAIL
  12. PaginationFailed
  13. JSONParsingFailed
  14. TheUserAlreadyExists
  15. AlreadyExists
  16. TheSystemIsAbnormal
  17. CodeIsError
  18. TheVerificationCodeWasNotSent
  19. AccountExists
  20. Theuseralreadyexists
  21. ThePhoneNumberIsWrong
  22. AnExceptionOccursWhenSendingAnSMSVerificationCode
  23. TokenIsFaild
  24. ThePasswordIsWrongOrThePhoneNumberIsIncorrect
  25. HasSend
  26. TheUserIsEmpty
  27. )
  28. var MsgFlags = map[Rescode]string{
  29. SUCCESS: "ok",
  30. ERROR: "fail",
  31. DELETEFAIL: "删除失败",
  32. TheUserAlreadyExists: "用户已存在",
  33. TheSystemIsAbnormal: "系统异常",
  34. CodeIsError: "验证码错误",
  35. UPDATEFAIL: "更新失败",
  36. Theuseralreadyexists: "用户已存在",
  37. JSONParsingFailed: "json解析失败",
  38. ThePhoneNumberIsWrong: "手机号错误",
  39. HasSend: "验证码已发送",
  40. AlreadyExists: "手机号已存在",
  41. AccountExists: "账号已存在",
  42. PaginationFailed: "分页查询失败",
  43. TheVerificationCodeWasNotSent: "验证码未发送",
  44. AnExceptionOccursWhenSendingAnSMSVerificationCode: "发送短信验证码出现异常",
  45. ThePasswordIsWrongOrThePhoneNumberIsIncorrect: "手机号或者密码错误",
  46. TokenIsInvalid: "Token 无效",
  47. TokenIsExpired: "Token 过期",
  48. TokenIsFaild: "Token 生成失败",
  49. TheUserIsEmpty: "用户为空",
  50. }
  51. func (c Rescode) GetMsg() string {
  52. // 检查Rescode是否在MsgFlags中定义,避免返回意外的消息
  53. msg, ok := MsgFlags[c]
  54. if ok {
  55. return msg
  56. } else {
  57. // 如果Rescode无效,则返回错误消息
  58. return MsgFlags[ERROR]
  59. }
  60. }