retmsg.go 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. package response
  2. import (
  3. "github.com/gin-gonic/gin"
  4. )
  5. var codeMsg map[int]string
  6. type Message struct {
  7. Code int `json:"code"`
  8. Msg string `json:"msg"`
  9. Data interface{} `json:"data,omitempty"`
  10. Token string `json:"token,omitempty"`
  11. Uid int `json:"uid,omitempty"`
  12. }
  13. //var MessageMap map[int]*Message
  14. func NewMessage(code int) *Message {
  15. if _, ok := codeMsg[code]; !ok {
  16. code = ERR_PARM
  17. }
  18. return &Message{
  19. Code: code,
  20. Msg: codeMsg[code],
  21. }
  22. }
  23. const (
  24. OK int = 200
  25. LOGOUT int = 401
  26. USER_PASWD_FAIL int = 402
  27. IP_ERR int = 404
  28. NOT_ADMIN int = 405
  29. PLOT_END int = 501
  30. ERR_PARM int = 10000
  31. ERR_SYS int = 10001
  32. DB_ERROR int = 10003
  33. ERR_PARSING int = 10004
  34. METHOD_ERR int = 10005
  35. PLAYER_NOT_EXIST int = 5205
  36. PLAYER_EXIST int = 5206
  37. FRIEND_ALREADY_INVITE int = 57001
  38. FRIEND_OFFLINE int = 57002
  39. USERNAME_NOT_EXIST int = 1021
  40. PASSWD_ERR int = 1022
  41. USERNAME_ERR int = 1025
  42. IDNUM_ERR int = 1026
  43. NAME_ERR int = 1027
  44. TPL_UPDATE_ERR int = 2001
  45. TRANS_FILE_ERR int = 3001
  46. TRANS_FILE_UPLOAD_ERR int = 3002
  47. TRANS_FILE_CREATE_ERR int = 3003
  48. TRANS_FILE_WRITE_ERR int = 3004
  49. SERVER_OFF int = 3005
  50. FILTER_LIST_ERR int = 4001
  51. )
  52. func init() {
  53. codeMsg = make(map[int]string)
  54. codeMsg[OK] = "成功"
  55. codeMsg[LOGOUT] = "用户未登陆"
  56. codeMsg[USER_PASWD_FAIL] = "用户名或密码错误"
  57. codeMsg[IP_ERR] = "IP不合法"
  58. codeMsg[NOT_ADMIN] = "非超级管理员"
  59. codeMsg[PLOT_END] = "剧情结束"
  60. codeMsg[ERR_PARM] = "参数错误"
  61. codeMsg[ERR_SYS] = "系统错误"
  62. codeMsg[DB_ERROR] = "数据库异常"
  63. codeMsg[ERR_PARSING] = "解析JSON出错"
  64. codeMsg[METHOD_ERR] = "Method not allowed"
  65. codeMsg[PLAYER_NOT_EXIST] = "玩家不存在"
  66. codeMsg[PLAYER_EXIST] = "玩家已存在"
  67. codeMsg[FRIEND_ALREADY_INVITE] = "已经申请"
  68. codeMsg[FRIEND_OFFLINE] = "对方离线"
  69. codeMsg[USERNAME_NOT_EXIST] = "用户不存在"
  70. codeMsg[PASSWD_ERR] = "密码错误"
  71. codeMsg[USERNAME_ERR] = "用户名异常"
  72. codeMsg[IDNUM_ERR] = "身份证号码异常"
  73. codeMsg[NAME_ERR] = "名字异常"
  74. codeMsg[TPL_UPDATE_ERR] = "模板今天数据更新失败"
  75. codeMsg[TRANS_FILE_ERR] = "transFile err"
  76. codeMsg[TRANS_FILE_UPLOAD_ERR] = "Read file error"
  77. codeMsg[TRANS_FILE_CREATE_ERR] = "Create file error"
  78. codeMsg[TRANS_FILE_WRITE_ERR] = "Write file error"
  79. codeMsg[SERVER_OFF] = "服务器关闭"
  80. codeMsg[FILTER_LIST_ERR] = "敏感词更新失败"
  81. }
  82. func ReturnErrMsg(code int, c *gin.Context) {
  83. // 开始时间
  84. c.JSON(200, NewMessage(code))
  85. }