example_client.go 616 B

1234567891011121314151617181920212223242526272829
  1. package clientImpl
  2. import (
  3. "../example"
  4. "context"
  5. "google.golang.org/grpc"
  6. "time"
  7. )
  8. func Call(c example.FormatDataClient, input string) (string, error) {
  9. ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
  10. defer cancel()
  11. r, err := c.DoFormat(ctx, &example.Data{Text: input})
  12. if err != nil {
  13. println("could not greet", err.Error())
  14. return "", err
  15. }
  16. return r.Text, nil
  17. }
  18. func MakeCalls(cc *grpc.ClientConn, n int) {
  19. hwc := example.NewFormatDataClient(cc)
  20. for i := 0; i < n; i++ {
  21. r, err := Call(hwc, "this is load balancing example")
  22. if nil == err {
  23. println(r)
  24. }
  25. }
  26. }