matches_handler.go 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. package handler
  2. import (
  3. "bet24.com/log"
  4. "bet24.com/servers/micros/matches/handler/combomatch"
  5. "bet24.com/servers/micros/matches/handler/matchbase"
  6. "bet24.com/servers/micros/matches/handler/pointmatch"
  7. "bet24.com/servers/micros/matches/handler/setsmatch"
  8. "bet24.com/servers/micros/matches/handler/simplematch"
  9. "bet24.com/servers/micros/matches/handler/singlematch"
  10. "bet24.com/servers/micros/matches/handler/sngmatch"
  11. pb "bet24.com/servers/micros/matches/proto"
  12. "context"
  13. "fmt"
  14. )
  15. var instance *MatchesService
  16. func GetInstance() *MatchesService {
  17. if instance == nil {
  18. instance = newHandler()
  19. }
  20. return instance
  21. }
  22. func Dump(cmd, param1, param2 string) {
  23. GetInstance().dump(cmd, param1, param2)
  24. }
  25. func newHandler() *MatchesService {
  26. ret := new(MatchesService)
  27. ret.ctor()
  28. return ret
  29. }
  30. type MatchesService struct{}
  31. func (h *MatchesService) ctor() {
  32. // 等服务启动后再启动自己
  33. go func() {
  34. matchbase.Run()
  35. simplematch.Run()
  36. pointmatch.Run()
  37. setsmatch.Run()
  38. sngmatch.Run()
  39. combomatch.Run()
  40. singlematch.Run()
  41. }()
  42. }
  43. func (d *MatchesService) dump(cmd, param1, param2 string) {
  44. switch cmd {
  45. case "simplematch":
  46. simplematch.Dump(param1, param2)
  47. case "pointmatch":
  48. pointmatch.Dump(param1, param2)
  49. case "sngmatch":
  50. sngmatch.Dump(param1, param2)
  51. case "combomatch":
  52. combomatch.Dump(param1, param2)
  53. case "setsmatch":
  54. setsmatch.Dump(param1, param2)
  55. case "singlematch":
  56. singlematch.Dump(param1, param2)
  57. default:
  58. log.Debug("MatchesService.dump %s,%s,%s", cmd, param1, param2)
  59. }
  60. }
  61. func (h *MatchesService) SayHello(ctx context.Context, req *pb.Request, rsp *pb.Response) error {
  62. rsp.Data = fmt.Sprintf("Hello from %s:%s", pb.ServiceName, req.Name)
  63. return nil
  64. }