You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

50 lines
2.0 KiB

  1. // Copyright 2015 Google Inc. All Rights Reserved.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. // Package transport supports network connections to HTTP and GRPC servers.
  15. // This package is not intended for use by end developers. Use the
  16. // google.golang.org/api/option package to configure API clients.
  17. package transport
  18. import (
  19. "net/http"
  20. "golang.org/x/net/context"
  21. "google.golang.org/grpc"
  22. "google.golang.org/api/option"
  23. gtransport "google.golang.org/api/transport/grpc"
  24. htransport "google.golang.org/api/transport/http"
  25. )
  26. // NewHTTPClient returns an HTTP client for use communicating with a Google cloud
  27. // service, configured with the given ClientOptions. It also returns the endpoint
  28. // for the service as specified in the options.
  29. func NewHTTPClient(ctx context.Context, opts ...option.ClientOption) (*http.Client, string, error) {
  30. return htransport.NewClient(ctx, opts...)
  31. }
  32. // DialGRPC returns a GRPC connection for use communicating with a Google cloud
  33. // service, configured with the given ClientOptions.
  34. func DialGRPC(ctx context.Context, opts ...option.ClientOption) (*grpc.ClientConn, error) {
  35. return gtransport.Dial(ctx, opts...)
  36. }
  37. // DialGRPCInsecure returns an insecure GRPC connection for use communicating
  38. // with fake or mock Google cloud service implementations, such as emulators.
  39. // The connection is configured with the given ClientOptions.
  40. func DialGRPCInsecure(ctx context.Context, opts ...option.ClientOption) (*grpc.ClientConn, error) {
  41. return gtransport.DialInsecure(ctx, opts...)
  42. }