code_msg.go 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. package e
  2. type Rescode int64
  3. const (
  4. SUCCESS Rescode = 200 + iota
  5. ERROR
  6. NOTTABLE
  7. )
  8. const (
  9. TokenIsInvalid Rescode = 1001 + iota
  10. TokenIsExpired
  11. DELETEFAIL
  12. UPDATEFAIL
  13. PaginationFailed
  14. JSONParsingFailed
  15. TheUserAlreadyExists
  16. AlreadyExists
  17. TheSystemIsAbnormal
  18. CodeIsError
  19. TheVerificationCodeWasNotSent
  20. AccountExists
  21. Theuseralreadyexists
  22. ThePhoneNumberIsWrong
  23. AnExceptionOccursWhenSendingAnSMSVerificationCode
  24. TokenIsFaild
  25. ThePasswordIsWrongOrThePhoneNumberIsIncorrect
  26. HasSend
  27. TheUserIsEmpty
  28. Repeat
  29. AddAppUserFail
  30. RegistrationFailed
  31. TheSystemCannotBeRegistered
  32. INSERTFAIL
  33. PleaseCheckTherRquiredFields
  34. TheParametersAreRepeated
  35. CAPISNOT
  36. ThereAreNoFeatures
  37. FINDFAIL
  38. LOGINFAIL
  39. NOTREGIST
  40. CollectionFAIL
  41. )
  42. var MsgFlags = map[Rescode]string{
  43. SUCCESS: "ok",
  44. ERROR: "fail",
  45. NOTTABLE: "该资源不存在",
  46. DELETEFAIL: "删除失败",
  47. TheUserAlreadyExists: "用户已存在",
  48. TheSystemIsAbnormal: "系统异常",
  49. CodeIsError: "验证码错误",
  50. UPDATEFAIL: "更新失败",
  51. Theuseralreadyexists: "用户已存在",
  52. JSONParsingFailed: "json解析失败",
  53. ThePhoneNumberIsWrong: "手机号格式错误",
  54. HasSend: "验证码已发送",
  55. AlreadyExists: "手机号已存在",
  56. AccountExists: "账号已存在",
  57. PaginationFailed: "分页查询失败",
  58. TheVerificationCodeWasNotSent: "验证码未发送",
  59. AnExceptionOccursWhenSendingAnSMSVerificationCode: "发送短信验证码出现异常",
  60. ThePasswordIsWrongOrThePhoneNumberIsIncorrect: "手机号或者密码错误",
  61. TokenIsInvalid: "Token 无效",
  62. TokenIsExpired: "Token 过期",
  63. TokenIsFaild: "Token 生成失败",
  64. TheUserIsEmpty: "用户为空",
  65. Repeat: "重复命名",
  66. AddAppUserFail: "添加用户失败",
  67. RegistrationFailed: "注册失败",
  68. TheSystemCannotBeRegistered: "该系统未开放注册",
  69. INSERTFAIL: "添加失败",
  70. PleaseCheckTherRquiredFields: "请检查必填项",
  71. TheParametersAreRepeated: "参数重复",
  72. CAPISNOT: "该功能不存在",
  73. ThereAreNoFeatures: "该系统未配置功能项,请前往添加",
  74. FINDFAIL: "查询失败",
  75. LOGINFAIL: "登录失败",
  76. NOTREGIST: "未注册请前往注册",
  77. CollectionFAIL: "收藏失败",
  78. }
  79. func (c Rescode) GetMsg() string {
  80. // 检查Rescode是否在MsgFlags中定义,避免返回意外的消息
  81. msg, ok := MsgFlags[c]
  82. if ok {
  83. return msg
  84. } else {
  85. // 如果Rescode无效,则返回错误消息
  86. return MsgFlags[ERROR]
  87. }
  88. }