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.
 
 
 

47 lines
1.8 KiB

  1. // Copyright 2015 Google LLC
  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
  15. import (
  16. "context"
  17. "net/http"
  18. "google.golang.org/grpc"
  19. "google.golang.org/api/option"
  20. gtransport "google.golang.org/api/transport/grpc"
  21. htransport "google.golang.org/api/transport/http"
  22. )
  23. // NewHTTPClient returns an HTTP client for use communicating with a Google cloud
  24. // service, configured with the given ClientOptions. It also returns the endpoint
  25. // for the service as specified in the options.
  26. func NewHTTPClient(ctx context.Context, opts ...option.ClientOption) (*http.Client, string, error) {
  27. return htransport.NewClient(ctx, opts...)
  28. }
  29. // DialGRPC returns a GRPC connection for use communicating with a Google cloud
  30. // service, configured with the given ClientOptions.
  31. func DialGRPC(ctx context.Context, opts ...option.ClientOption) (*grpc.ClientConn, error) {
  32. return gtransport.Dial(ctx, opts...)
  33. }
  34. // DialGRPCInsecure returns an insecure GRPC connection for use communicating
  35. // with fake or mock Google cloud service implementations, such as emulators.
  36. // The connection is configured with the given ClientOptions.
  37. func DialGRPCInsecure(ctx context.Context, opts ...option.ClientOption) (*grpc.ClientConn, error) {
  38. return gtransport.DialInsecure(ctx, opts...)
  39. }