infoc.go 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. package region
  2. import (
  3. "bytes"
  4. "strconv"
  5. "time"
  6. "go-common/app/interface/main/app-feed/model/tag"
  7. "go-common/library/log"
  8. binfoc "go-common/library/log/infoc"
  9. )
  10. type tagsInfoc struct {
  11. typ string
  12. mid string
  13. client string
  14. build string
  15. buvid string
  16. disid string
  17. ip string
  18. api string
  19. now string
  20. tags []*tag.Tag
  21. }
  22. type tagInfoc struct {
  23. typ string
  24. mid string
  25. client string
  26. build string
  27. buvid string
  28. disid string
  29. ip string
  30. api string
  31. now string
  32. rid string
  33. tid string
  34. }
  35. func (s *Service) TagsInfoc(mid int64, plat int8, build int, buvid, disid, ip, api string, tags []*tag.Tag, now time.Time) {
  36. select {
  37. case s.logCh <- tagsInfoc{"推荐页入口", strconv.FormatInt(mid, 10), strconv.Itoa(int(plat)), strconv.Itoa(build), buvid, disid, ip, api, strconv.FormatInt(now.Unix(), 10), tags}:
  38. default:
  39. log.Warn("infoc log buffer is full")
  40. }
  41. }
  42. func (s *Service) ChangeTagsInfoc(mid int64, plat int8, build int, buvid, disid, ip, api string, tags []*tag.Tag, now time.Time) {
  43. select {
  44. case s.logCh <- tagsInfoc{"换一换", strconv.FormatInt(mid, 10), strconv.Itoa(int(plat)), strconv.Itoa(build), buvid, disid, ip, api, strconv.FormatInt(now.Unix(), 10), tags}:
  45. default:
  46. log.Warn("infoc log buffer is full")
  47. }
  48. }
  49. func (s *Service) AddTagInfoc(mid int64, plat int8, build int, buvid, disid, ip, api string, rid int, tid int64, now time.Time) {
  50. select {
  51. case s.logCh <- tagInfoc{"订阅标签", strconv.FormatInt(mid, 10), strconv.Itoa(int(plat)), strconv.Itoa(build), buvid, disid, ip, api, strconv.FormatInt(now.Unix(), 10), strconv.Itoa(rid), strconv.FormatInt(tid, 10)}:
  52. default:
  53. log.Warn("infoc log buffer is full")
  54. }
  55. }
  56. func (s *Service) CancelTagInfoc(mid int64, plat int8, build int, buvid, disid, ip, api string, rid int, tid int64, now time.Time) {
  57. select {
  58. case s.logCh <- tagInfoc{"取消标签", strconv.FormatInt(mid, 10), strconv.Itoa(int(plat)), strconv.Itoa(build), buvid, disid, ip, api, strconv.FormatInt(now.Unix(), 10), strconv.Itoa(rid), strconv.FormatInt(tid, 10)}:
  59. default:
  60. log.Warn("infoc log buffer is full")
  61. }
  62. }
  63. // writeInfoc
  64. func (s *Service) infocproc() {
  65. const (
  66. // infoc format {"section":{"id":"%s","pos":1,"items":[{"id":%s,"pos":%d,"url":""}]}}
  67. noItem1 = `{"section":{"id":"`
  68. noItem2 = `","pos":1,"items":[]}}`
  69. )
  70. var (
  71. msg1 = []byte(`{"section":{"id":"`)
  72. msg2 = []byte(`","pos":1,"items":[`)
  73. msg3 = []byte(`{"id":`)
  74. msg4 = []byte(`,"name":"`)
  75. msg5 = []byte(`","url":""},`)
  76. msg6 = []byte(`]}}`)
  77. inf2 = binfoc.New(s.c.TagInfoc2)
  78. buf bytes.Buffer
  79. list string
  80. )
  81. for {
  82. i, ok := <-s.logCh
  83. if !ok {
  84. log.Warn("infoc proc exit")
  85. return
  86. }
  87. switch v := i.(type) {
  88. case tagsInfoc:
  89. if len(v.tags) > 0 {
  90. buf.Write(msg1)
  91. buf.WriteString(v.typ)
  92. buf.Write(msg2)
  93. for _, v := range v.tags {
  94. buf.Write(msg3)
  95. buf.WriteString(strconv.FormatInt(v.ID, 10))
  96. buf.Write(msg4)
  97. buf.WriteString(v.Name)
  98. buf.Write(msg5)
  99. }
  100. buf.Truncate(buf.Len() - 1)
  101. buf.Write(msg6)
  102. list = buf.String()
  103. buf.Reset()
  104. } else {
  105. list = noItem1 + v.typ + noItem2
  106. }
  107. inf2.Info(v.ip, v.now, v.api, v.buvid, v.mid, v.client, "1", list, v.disid, "1", v.build)
  108. case tagInfoc:
  109. inf2.Info(v.ip, v.now, v.api, v.buvid, v.mid, v.client, "1", list, v.disid, "1", v.build)
  110. }
  111. }
  112. }