pb.go 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. package proto
  2. import (
  3. "bet24.com/log"
  4. "bet24.com/servers/micros/common"
  5. "github.com/smallnest/rpcx/client"
  6. "golang.org/x/net/context"
  7. )
  8. const ServiceName = "guess"
  9. var consulAddr = common.Default_Consul_Addr
  10. func getClient() client.XClient {
  11. return common.GetClientPool().GetClient(ServiceName, consulAddr)
  12. }
  13. type Request struct {
  14. UserId int `json:",omitempty"` // 用户id
  15. SerialNumber string `json:",omitempty"` // 赛事流水号
  16. Title string `json:",omitempty"` // 赛事标题
  17. Result string `json:",omitempty"` // 赛事结果
  18. Status int `json:",omitempty"` // 赛事状态
  19. Type int `json:",omitempty"` // 赛事类型
  20. StartAt string `json:",omitempty"` // 赛事开始时间
  21. EndAt string `json:",omitempty"` // 赛事结束时间
  22. ShowStartAt string `json:",omitempty"` // 赛事展示开始时间
  23. ShowEndAt string `json:",omitempty"` // 赛事展示截止时间
  24. TeamId int `json:",omitempty"` // 球队id
  25. BetId int `json:",omitempty"` // 投注id
  26. Amount int `json:",omitempty"` // 投注金额
  27. BetName string `json:",omitempty"` // 投注名称
  28. BetOdds float64 `json:",omitempty"` // 投注赔率
  29. PageIndex int `json:",omitempty"` // 页索引
  30. PageSize int `json:",omitempty"` // 页大小
  31. Rid int `json:",omitempty"` // 标识
  32. OpUser `json:",omitempty"` // 操作员
  33. Msg string
  34. Data string
  35. }
  36. type Response struct {
  37. Data string
  38. }
  39. type Response_Match struct {
  40. Match
  41. UserBets []UserBet
  42. }
  43. func SetConsulAddr(addr string) {
  44. consulAddr = addr
  45. }
  46. // 消息处理
  47. func OnGuessMsg(userId int, msg, data string) string {
  48. xclient := getClient()
  49. //defer xclient.Close()
  50. args := &Request{
  51. UserId: userId,
  52. Msg: msg,
  53. Data: data,
  54. }
  55. reply := &Response{}
  56. err := xclient.Call(context.Background(), "OnGuessMsg", args, reply)
  57. if err != nil {
  58. log.Debug("OnGuessMsg failed to call: %v", err)
  59. common.GetClientPool().RemoveClient(ServiceName)
  60. }
  61. return reply.Data
  62. }