api: google.golang.org/api/transport Index | Examples | Files | Directories

package transport

import "google.golang.org/api/transport"

Package transport provides utility methods for creating authenticated transports to Google's HTTP and gRPC APIs. It is intended to be used in conjunction with google.golang.org/api/option.

This package is not intended for use by end developers. Use the google.golang.org/api/option package to configure API clients.

Code:

ctx := context.Background()

// Providing no auth option will cause NewClient to look for Application
// Default Creds as specified at https://godoc.org/golang.org/x/oauth2/google#FindDefaultCredentials.
//
// Note: Given the same set of options, transport.NewHTTPClient and
// transport.DialGRPC use the same credentials.
c, _, err := transport.NewHTTPClient(ctx)
if err != nil {
    log.Fatal(err)
}
_ = c // Use authenticated client.

Code:

ctx := context.Background()

// Download service account creds per https://cloud.google.com/docs/authentication/production.
//
// Note: Given the same set of options, transport.NewHTTPClient and
// transport.DialGRPC use the same credentials.
c, _, err := transport.NewHTTPClient(ctx, option.WithCredentialsFile("/path/to/service-account-creds.json"))
if err != nil {
    log.Fatal(err)
}
_ = c // Use authenticated client.

Index

Examples

Package Files

dial.go doc.go go19.go

func Creds Uses

func Creds(ctx context.Context, opts ...option.ClientOption) (*google.Credentials, error)

Creds constructs a google.Credentials from the information in the options, or obtains the default credentials in the same way as google.FindDefaultCredentials.

func DialGRPC Uses

func DialGRPC(ctx context.Context, opts ...option.ClientOption) (*grpc.ClientConn, error)

DialGRPC returns a GRPC connection for use communicating with a Google cloud service, configured with the given ClientOptions.

func DialGRPCInsecure Uses

func DialGRPCInsecure(ctx context.Context, opts ...option.ClientOption) (*grpc.ClientConn, error)

DialGRPCInsecure returns an insecure GRPC connection for use communicating with fake or mock Google cloud service implementations, such as emulators. The connection is configured with the given ClientOptions.

func NewHTTPClient Uses

func NewHTTPClient(ctx context.Context, opts ...option.ClientOption) (*http.Client, string, error)

NewHTTPClient returns an HTTP client for use communicating with a Google cloud service, configured with the given ClientOptions. It also returns the endpoint for the service as specified in the options.

Directories

PathSynopsis
bytestreamPackage bytestream provides a client for any service that exposes a ByteStream API.
bytestream/internal
grpcPackage grpc supports network connections to GRPC servers.
httpPackage http supports network connections to HTTP servers.
http/internal/propagationPackage propagation implements X-Cloud-Trace-Context header propagation used by Google Cloud products.

Package transport imports 8 packages (graph) and is imported by 85 packages. Updated 2019-07-20. Refresh now. Tools for package owners.