code_msg.go 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. GoToRegister
  28. )
  29. var MsgFlags = map[Rescode]string{
  30. SUCCESS: "ok",
  31. ERROR: "fail",
  32. DELETEFAIL: "删除失败",
  33. TheUserAlreadyExists: "用户已存在",
  34. TheSystemIsAbnormal: "系统异常",
  35. CodeIsError: "验证码错误",
  36. UPDATEFAIL: "更新失败",
  37. Theuseralreadyexists: "用户已存在",
  38. JSONParsingFailed: "json解析失败",
  39. ThePhoneNumberIsWrong: "手机号错误",
  40. HasSend: "验证码已发送",
  41. AlreadyExists: "手机号已存在",
  42. AccountExists: "账号已存在",
  43. PaginationFailed: "分页查询失败",
  44. TheVerificationCodeWasNotSent: "验证码未发送",
  45. AnExceptionOccursWhenSendingAnSMSVerificationCode: "发送短信验证码出现异常",
  46. ThePasswordIsWrongOrThePhoneNumberIsIncorrect: "手机号或者密码错误",
  47. TokenIsInvalid: "Token 无效",
  48. TokenIsExpired: "Token 过期",
  49. TokenIsFaild: "Token 生成失败",
  50. TheUserIsEmpty: "用户为空",
  51. GoToRegister: "请前往注册",
  52. }
  53. func (c Rescode) GetMsg() string {
  54. // 检查Rescode是否在MsgFlags中定义,避免返回意外的消息
  55. msg, ok := MsgFlags[c]
  56. if ok {
  57. return msg
  58. } else {
  59. // 如果Rescode无效,则返回错误消息
  60. return MsgFlags[ERROR]
  61. }
  62. }