pb.go 845 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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 = "money"
  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. Name string
  15. }
  16. type Response struct {
  17. Data string
  18. }
  19. func SetConsulAddr(addr string) {
  20. consulAddr = addr
  21. }
  22. func SayHello(name string) string {
  23. xclient := getClient()
  24. //defer xclient.Close()
  25. args := &Request{
  26. Name: name,
  27. }
  28. reply := &Response{}
  29. err := xclient.Call(context.Background(), "SayHello", args, reply)
  30. if err != nil {
  31. log.Debug("money failed to call: %v", err)
  32. common.GetClientPool().RemoveClient(ServiceName)
  33. return ""
  34. }
  35. log.Debug("SayHello return %s", reply.Data)
  36. return reply.Data
  37. }