pb.go 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. package proto
  2. import (
  3. "bet24.com/log"
  4. "bet24.com/servers/micros/common"
  5. "context"
  6. "github.com/smallnest/rpcx/client"
  7. )
  8. const ServiceName = "slotsservice"
  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. GameName string
  15. UserId int
  16. IsChip bool
  17. Amount int
  18. Extra string
  19. }
  20. type Response struct {
  21. Data string
  22. Success bool
  23. Amount int
  24. }
  25. func SetConsulAddr(addr string) {
  26. consulAddr = addr
  27. }
  28. func SayHello(name string) string {
  29. xclient := getClient()
  30. args := &Request{
  31. GameName: name,
  32. }
  33. reply := &Response{}
  34. err := xclient.Call(context.Background(), "SayHello", args, reply)
  35. if err != nil {
  36. log.Debug("slotsservice.SayHello failed to call: %v", err)
  37. common.GetClientPool().RemoveClient(ServiceName)
  38. return ""
  39. }
  40. log.Debug("SayHello return %s", reply.Data)
  41. return reply.Data
  42. }
  43. func GetSlotsConfig(gameName string, userId int) string {
  44. xclient := getClient()
  45. args := &Request{
  46. GameName: gameName,
  47. UserId: userId,
  48. }
  49. reply := &Response{}
  50. err := xclient.Call(context.Background(), "GetSlotsConfig", args, reply)
  51. if err != nil {
  52. log.Debug("slotsservice.GetSlotsConfig failed to call: %v", err)
  53. common.GetClientPool().RemoveClient(ServiceName)
  54. return ""
  55. }
  56. return reply.Data
  57. }
  58. func Spin(gameName string, userId int, amount int, isChip bool, extra string) (bool, int, string) {
  59. xclient := getClient()
  60. args := &Request{
  61. GameName: gameName,
  62. UserId: userId,
  63. Amount: amount,
  64. IsChip: isChip,
  65. Extra: extra,
  66. }
  67. reply := &Response{}
  68. err := xclient.Call(context.Background(), "Spin", args, reply)
  69. if err != nil {
  70. log.Debug("slotsservice.Spin failed to call: %v", err)
  71. common.GetClientPool().RemoveClient(ServiceName)
  72. return false, 0, "server error"
  73. }
  74. return reply.Success, reply.Amount, reply.Data
  75. }