infoc.go 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. package service
  2. import (
  3. "go-common/library/log"
  4. "go-common/library/log/infoc"
  5. "strconv"
  6. "time"
  7. )
  8. var inCh = make(chan interface{}, 10240)
  9. const maxInt = int(^uint(0) >> 1)
  10. type bagLogInfoc struct {
  11. id string
  12. uid string
  13. bagID string
  14. giftID string
  15. num string
  16. afterNum string
  17. source string
  18. infoType string
  19. ctime string
  20. }
  21. type giftActionInfoc struct {
  22. uid int64
  23. roomid int64
  24. item int64
  25. value int64
  26. change int64
  27. describe string
  28. extra string
  29. ts int64
  30. platform string
  31. clientver string
  32. buvid string
  33. ua string
  34. referer string
  35. }
  36. // bagLogInfoc 包裹日志打点
  37. func (s *Service) bagLogInfoc(uid, bagID, giftID, num, afterNum int64, source string) {
  38. s.infoc(bagLogInfoc{
  39. id: MakeID(uid),
  40. uid: strconv.FormatInt(uid, 10),
  41. bagID: strconv.FormatInt(bagID, 10),
  42. giftID: strconv.FormatInt(giftID, 10),
  43. num: strconv.FormatInt(num, 10),
  44. afterNum: strconv.FormatInt(afterNum, 10),
  45. source: source,
  46. infoType: "1",
  47. ctime: time.Now().Format("2006-01-02 15:04:05"),
  48. })
  49. }
  50. //giftActionInfoc 道具打点
  51. func (s *Service) giftActionInfoc(uid, roomid, item, value, change int64, describe, platform string) {
  52. s.infoc(giftActionInfoc{
  53. uid: uid,
  54. roomid: roomid,
  55. item: item,
  56. value: value,
  57. change: change,
  58. describe: describe,
  59. extra: "",
  60. ts: time.Now().Unix(),
  61. platform: platform,
  62. clientver: "",
  63. buvid: "",
  64. ua: "",
  65. referer: "",
  66. })
  67. }
  68. // MakeID MakeID
  69. func MakeID(uid int64) string {
  70. prefix := strconv.FormatInt(uid%10, 10)
  71. postfix := strconv.Itoa(maxInt - int(time.Now().Unix()*10000))
  72. uidStr := strconv.FormatInt(uid, 10)
  73. l := len(uidStr)
  74. var middle string
  75. if l >= 10 {
  76. middle = uidStr
  77. } else {
  78. var s string
  79. for i := 0; i < (10 - l); i++ {
  80. s += "0"
  81. }
  82. middle = s + uidStr
  83. }
  84. return prefix + middle + postfix
  85. }
  86. //infoc
  87. func (s *Service) infoc(i interface{}) {
  88. select {
  89. case inCh <- i:
  90. default:
  91. log.Warn("infocproc chan full")
  92. }
  93. }
  94. // infocproc
  95. func (s *Service) infocproc() {
  96. var bl = infoc.New(s.c.Infoc["bagLog"])
  97. var ga = infoc.New(s.c.Infoc["giftAction"])
  98. for {
  99. i := <-inCh
  100. switch v := i.(type) {
  101. case bagLogInfoc:
  102. err := bl.Info(v.id, v.uid, v.bagID, v.giftID, v.num, v.afterNum, v.source, v.infoType, v.ctime)
  103. log.Info("bagLogInfoc info %v,ret:%v", v, err)
  104. case giftActionInfoc:
  105. err := ga.Info(v.uid, v.roomid, v.item, v.value, v.change, v.describe, v.extra, v.ts, v.platform, v.clientver, v.buvid, v.ua, v.referer)
  106. log.Info("giftActionInfoc info %v,ret:%v", v, err)
  107. default:
  108. log.Warn("infocproc can't process the type")
  109. }
  110. }
  111. }