pb.go 989 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package proto
  2. import (
  3. "bet24.com/log"
  4. "bet24.com/servers/micros/common"
  5. item "bet24.com/servers/micros/item_inventory/proto"
  6. "context"
  7. "github.com/smallnest/rpcx/client"
  8. )
  9. const ServiceName = "highly_profitable"
  10. var consulAddr = common.Default_Consul_Addr
  11. func getClient() client.XClient {
  12. return common.GetClientPool().GetClient(ServiceName, consulAddr)
  13. }
  14. type Request struct {
  15. Name string
  16. UserId int
  17. }
  18. type Response struct {
  19. Success bool
  20. Data string
  21. Items []item.ItemPack
  22. List UserStageTask
  23. }
  24. func SetConsulAddr(addr string) {
  25. consulAddr = addr
  26. }
  27. func SayHello(name string) string {
  28. xclient := getClient()
  29. //defer xclient.Close()
  30. args := &Request{
  31. Name: name,
  32. }
  33. reply := &Response{}
  34. err := xclient.Call(context.Background(), "SayHello", args, reply)
  35. if err != nil {
  36. log.Debug("task 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. }