msg.go 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. package model
  2. import (
  3. "encoding/json"
  4. "strconv"
  5. "go-common/library/log"
  6. "github.com/pkg/errors"
  7. )
  8. // MsgCanal canal message struct
  9. type MsgCanal struct {
  10. Action string `json:"action"`
  11. Table string `json:"table"`
  12. New json.RawMessage `json:"new"`
  13. Old json.RawMessage `json:"old"`
  14. }
  15. // MsgVipInfo message for user vip staus
  16. type MsgVipInfo struct {
  17. Mid int64 `json:"mid"`
  18. Type int8 `json:"type"`
  19. Timestamp int64 `json:"ts"`
  20. }
  21. type MsgAccountLog struct {
  22. Mid int64 `json:"mid"`
  23. IP string `json:"ip"`
  24. TS int64 `json:"ts"`
  25. Content map[string]string `json:"content"`
  26. }
  27. func (m *MsgAccountLog) ExpFrom() (exp int) {
  28. var (
  29. fromExp = m.Content["from_exp"]
  30. err error
  31. )
  32. if exp, err = strconv.Atoi(fromExp); err != nil {
  33. err = errors.Wrapf(err, "fromExp (%s)", fromExp)
  34. log.Error("%+v", err)
  35. exp = 0
  36. }
  37. return
  38. }
  39. func (m *MsgAccountLog) ExpTo() (exp int) {
  40. var (
  41. toExp = m.Content["to_exp"]
  42. err error
  43. )
  44. if exp, err = strconv.Atoi(toExp); err != nil {
  45. err = errors.Wrapf(err, "toExp (%s)", toExp)
  46. log.Error("%+v", err)
  47. exp = 0
  48. }
  49. return
  50. }
  51. func (m *MsgAccountLog) IsViewExp() bool {
  52. var (
  53. operater = m.Content["operater"]
  54. )
  55. return operater == "watch"
  56. }