example.pb.go 824 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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 = "example"
  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. args := &Request{
  25. Name: name,
  26. }
  27. reply := &Response{}
  28. err := xclient.Call(context.Background(), "SayHello", args, reply)
  29. if err != nil {
  30. log.Debug("example failed to call: %v", err)
  31. common.GetClientPool().RemoveClient(ServiceName)
  32. return ""
  33. }
  34. log.Debug("SayHello return %s", reply.Data)
  35. return reply.Data
  36. }