...

Source file src/google.golang.org/api/transport/dial.go

Documentation: google.golang.org/api/transport

     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  
     5  package transport
     6  
     7  import (
     8  	"context"
     9  	"net/http"
    10  
    11  	"golang.org/x/oauth2/google"
    12  	"google.golang.org/grpc"
    13  
    14  	"google.golang.org/api/internal"
    15  	"google.golang.org/api/option"
    16  	gtransport "google.golang.org/api/transport/grpc"
    17  	htransport "google.golang.org/api/transport/http"
    18  )
    19  
    20  // NewHTTPClient returns an HTTP client for use communicating with a Google cloud
    21  // service, configured with the given ClientOptions. It also returns the endpoint
    22  // for the service as specified in the options.
    23  func NewHTTPClient(ctx context.Context, opts ...option.ClientOption) (*http.Client, string, error) {
    24  	return htransport.NewClient(ctx, opts...)
    25  }
    26  
    27  // DialGRPC returns a GRPC connection for use communicating with a Google cloud
    28  // service, configured with the given ClientOptions.
    29  func DialGRPC(ctx context.Context, opts ...option.ClientOption) (*grpc.ClientConn, error) {
    30  	return gtransport.Dial(ctx, opts...)
    31  }
    32  
    33  // DialGRPCInsecure returns an insecure GRPC connection for use communicating
    34  // with fake or mock Google cloud service implementations, such as emulators.
    35  // The connection is configured with the given ClientOptions.
    36  func DialGRPCInsecure(ctx context.Context, opts ...option.ClientOption) (*grpc.ClientConn, error) {
    37  	return gtransport.DialInsecure(ctx, opts...)
    38  }
    39  
    40  // Creds constructs a google.Credentials from the information in the options,
    41  // or obtains the default credentials in the same way as google.FindDefaultCredentials.
    42  func Creds(ctx context.Context, opts ...option.ClientOption) (*google.Credentials, error) {
    43  	var ds internal.DialSettings
    44  	for _, opt := range opts {
    45  		opt.Apply(&ds)
    46  	}
    47  	return internal.Creds(ctx, &ds)
    48  }
    49  

View as plain text