servicecontext.go 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. package svc
  2. import (
  3. "ylink/comm/ds/treemap"
  4. "ylink/comm/kafka"
  5. "ylink/comm/model"
  6. "ylink/core/inner/rpc/internal/config"
  7. "ylink/core/inner/rpc/internal/ext"
  8. )
  9. type ServiceContext struct {
  10. Config config.Config
  11. KqMsgBoxProducer *kafka.Producer
  12. }
  13. func NewServiceContext(c config.Config) *ServiceContext {
  14. fetchCsCenterInfo()
  15. return &ServiceContext{
  16. Config: c,
  17. KqMsgBoxProducer: kafka.NewKafkaProducer(c.KqMsgBoxProducerConf.Brokers, c.KqMsgBoxProducerConf.Topic),
  18. }
  19. }
  20. func fetchCsCenterInfo() {
  21. // mock info
  22. mockInfo()
  23. }
  24. func mockInfo() {
  25. ext.IdMap = treemap.New(treemap.WithGoroutineSafe())
  26. ext.CsMap = treemap.New(treemap.WithGoroutineSafe())
  27. // 已连接的映射
  28. // 专属客服映射
  29. game1231P2cMap := treemap.New(treemap.WithGoroutineSafe())
  30. game1231P2cMap.Insert("player1231", "cs_1231")
  31. game1231P2cMap.Insert("player1111", "cs_2222")
  32. game1111P2cMap := treemap.New(treemap.WithGoroutineSafe())
  33. game1111P2cMap.Insert("player1231", "cs_1111")
  34. ext.IdMap.Insert("game1231", game1231P2cMap)
  35. ext.IdMap.Insert("game1111", game1111P2cMap)
  36. ext.CsMap.Insert("cs_1231", &model.CsInfo{
  37. CsId: "cs_1231",
  38. CsNickname: "客服1231",
  39. CsAvatarUrl: "https://www.baidu.com",
  40. CsSignature: "我是客服1231",
  41. OnlineStatus: 1,
  42. })
  43. ext.CsMap.Insert("cs_1111", &model.CsInfo{
  44. CsId: "cs_1111",
  45. CsNickname: "客服1111",
  46. CsAvatarUrl: "https://www.baidu.com",
  47. CsSignature: "我是客服1111",
  48. OnlineStatus: 1,
  49. })
  50. ext.CsMap.Insert("cs_2222", &model.CsInfo{
  51. CsId: "cs_2222",
  52. CsNickname: "客服2222",
  53. CsAvatarUrl: "https://www.baidu.com",
  54. CsSignature: "我是客服2222",
  55. OnlineStatus: 0,
  56. })
  57. }