code_msg.go 2.1 KB

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