code_msg.go 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. package e
  2. type Rescode int64
  3. func (c Rescode) Error() string {
  4. //TODO implement me
  5. panic("implement me")
  6. }
  7. const (
  8. SUCCESS Rescode = 200 + iota
  9. ERROR
  10. )
  11. const (
  12. TokenIsInvalid Rescode = 1001 + iota
  13. TokenIsExpired
  14. DELETEFAIL
  15. UPDATEFAIL
  16. FINDFAIL
  17. DeleteFail
  18. PaginationFailed
  19. JSONParsingFailed
  20. TheUserAlreadyExists
  21. AlreadyExists
  22. TheSystemIsAbnormal
  23. CodeIsError
  24. Theuseralreadyexists
  25. ThePhoneNumberIsWrong
  26. AnExceptionOccursWhenSendingAnSMSVerificationCode
  27. TokenIsFaild
  28. ThePasswordIsWrongOrThePhoneNumberIsIncorrect
  29. HasSend
  30. TheUserIsEmpty
  31. TheParameterCannotBeEmpty
  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. PaginationFailed: "分页查询失败",
  47. FINDFAIL: "查询失败",
  48. DeleteFail: "删除失败",
  49. TheParameterCannotBeEmpty: "参数不能为空",
  50. AnExceptionOccursWhenSendingAnSMSVerificationCode: "发送短信验证码出现异常",
  51. ThePasswordIsWrongOrThePhoneNumberIsIncorrect: "手机号或者密码错误",
  52. TokenIsInvalid: "Token 无效",
  53. TokenIsExpired: "Token 过期",
  54. TokenIsFaild: "Token 生成失败",
  55. TheUserIsEmpty: "用户为空",
  56. }
  57. func (c Rescode) GetMsg() string {
  58. // 检查Rescode是否在MsgFlags中定义,避免返回意外的消息
  59. msg, ok := MsgFlags[c]
  60. if ok {
  61. return msg
  62. } else {
  63. // 如果Rescode无效,则返回错误消息
  64. return MsgFlags[ERROR]
  65. }
  66. }