dial.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536
  1. // Copyright 2015 Google LLC.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. package transport
  5. import (
  6. "context"
  7. "net/http"
  8. "google.golang.org/grpc"
  9. "google.golang.org/api/option"
  10. gtransport "google.golang.org/api/transport/grpc"
  11. htransport "google.golang.org/api/transport/http"
  12. )
  13. // NewHTTPClient returns an HTTP client for use communicating with a Google cloud
  14. // service, configured with the given ClientOptions. It also returns the endpoint
  15. // for the service as specified in the options.
  16. func NewHTTPClient(ctx context.Context, opts ...option.ClientOption) (*http.Client, string, error) {
  17. return htransport.NewClient(ctx, opts...)
  18. }
  19. // DialGRPC returns a GRPC connection for use communicating with a Google cloud
  20. // service, configured with the given ClientOptions.
  21. func DialGRPC(ctx context.Context, opts ...option.ClientOption) (*grpc.ClientConn, error) {
  22. return gtransport.Dial(ctx, opts...)
  23. }
  24. // DialGRPCInsecure returns an insecure GRPC connection for use communicating
  25. // with fake or mock Google cloud service implementations, such as emulators.
  26. // The connection is configured with the given ClientOptions.
  27. func DialGRPCInsecure(ctx context.Context, opts ...option.ClientOption) (*grpc.ClientConn, error) {
  28. return gtransport.DialInsecure(ctx, opts...)
  29. }