pb.go 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. package proto
  2. import (
  3. "context"
  4. "bet24.com/log"
  5. "bet24.com/servers/micros/common"
  6. item "bet24.com/servers/micros/item_inventory/proto"
  7. task "bet24.com/servers/micros/task/proto"
  8. "github.com/smallnest/rpcx/client"
  9. )
  10. const ServiceName = "activityservice"
  11. var consulAddr = common.Default_Consul_Addr
  12. func getClient() client.XClient {
  13. return common.GetClientPool().GetClient(ServiceName, consulAddr)
  14. }
  15. type Request struct {
  16. Name string
  17. UserId int
  18. DayIndex int
  19. Action int
  20. Progress int
  21. IsFinalPackage bool
  22. Param task.TaskScope
  23. TermId int
  24. PackageId int
  25. ProductId string
  26. Level int // 当前等级
  27. NewLevel int // 等级变化
  28. IsAll bool
  29. GameId int // 游戏id
  30. WinAmount int // 赢取金币
  31. IsOld bool
  32. }
  33. type Response struct {
  34. RetCode int
  35. Success bool
  36. Data string
  37. SysData NoviceWelfare
  38. UserWelfare UserNoviceWelfare
  39. Items []item.ItemPack
  40. Amount int
  41. }
  42. func SetConsulAddr(addr string) {
  43. consulAddr = addr
  44. }
  45. func SayHello(name string) string {
  46. xclient := getClient()
  47. //defer xclient.Close()
  48. args := &Request{
  49. Name: name,
  50. }
  51. reply := &Response{}
  52. err := xclient.Call(context.Background(), "SayHello", args, reply)
  53. if err != nil {
  54. log.Debug("%s failed to call: %v", ServiceName, err)
  55. common.GetClientPool().RemoveClient(ServiceName)
  56. return ""
  57. }
  58. log.Debug("activityservice return %s", reply.Data)
  59. return reply.Data
  60. }
  61. func AddUser(userId int) {
  62. xclient := getClient()
  63. //defer xclient.Close()
  64. args := &Request{
  65. UserId: userId,
  66. }
  67. err := xclient.Call(context.Background(), "AddUser", args, nil)
  68. if err != nil {
  69. common.GetClientPool().RemoveClient(ServiceName)
  70. log.Debug("activityservice failed to call: %v", err)
  71. }
  72. }
  73. func RemoveUser(userId int) {
  74. xclient := getClient()
  75. //defer xclient.Close()
  76. args := &Request{
  77. UserId: userId,
  78. }
  79. err := xclient.Call(context.Background(), "RemoveUser", args, nil)
  80. if err != nil {
  81. common.GetClientPool().RemoveClient(ServiceName)
  82. log.Debug("activityservice failed to call: %v", err)
  83. }
  84. }