xhalls.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. package scratchcard
  2. import (
  3. "active/tools"
  4. "encoding/json"
  5. "fmt"
  6. "git.jiaxianghudong.com/webs/pkg/hall"
  7. "log"
  8. "sync"
  9. )
  10. var (
  11. sendPool = sync.Pool{
  12. New: func() interface{} { return new(MsgFormat) },
  13. }
  14. hallSend chan *MsgFormat
  15. )
  16. type MsgFormat struct {
  17. NoticeList []uint32 `json:"-"`
  18. Data interface{} `json:"data"`
  19. }
  20. type Formt struct {
  21. Notice int64 `json:"notice"`
  22. Name string `json:"name"`
  23. CardNumber int64 `json:"card_number"`
  24. }
  25. type HallConfig struct {
  26. HallConfig []*hall.Server `json:"hall_config" yaml:"hall_config"`
  27. }
  28. func SendOrchardMsg(msg Formt, userid uint32) {
  29. msgFormat := sendPool.Get().(*MsgFormat)
  30. msgFormat.NoticeList = []uint32{userid}
  31. msgFormat.Data = msg
  32. return
  33. hallSend <- msgFormat
  34. }
  35. func LoopSend() {
  36. config := HallConfig{}
  37. hallSend = make(chan *MsgFormat)
  38. tools.ReloadConfig("./active.yaml", &config)
  39. err := hall.InitClientCluster(&hall.Config{
  40. Servers: config.HallConfig,
  41. })
  42. if err != nil {
  43. fmt.Println("没有配置", err)
  44. return
  45. }
  46. fmt.Println(config.HallConfig)
  47. for {
  48. select {
  49. case msg := <-hallSend:
  50. //log.Println("发送: ",msg)
  51. listJson, _ := json.Marshal(msg)
  52. listJson = append(listJson, 0)
  53. err := hall.UserNotifier().Go(msg.NoticeList, "gbwdd", "", listJson)
  54. if err != nil {
  55. log.Println(err)
  56. }
  57. msg.NoticeList = make([]uint32, 0)
  58. sendPool.Put(msg)
  59. }
  60. }
  61. }