code_msg.go 1.6 KB

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