Cloud Spanner API v1 - Package cloud.google.com/go/spanner/apiv1 (v1.44.0)

Package spanner is an auto-generated package for the Cloud Spanner API.

Cloud Spanner is a managed, mission-critical, globally consistent and scalable relational database service.

General documentation

For information about setting deadlines, reusing contexts, and more please visit https://pkg.go.dev/cloud.google.com/go.

Example usage

To get started with this package, create a client.

ctx := context.Background()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := spanner.NewClient(ctx)
if err != nil {
    // TODO: Handle error.
}
defer c.Close()

The client will use your default application credentials. Clients should be reused instead of created as needed. The methods of Client are safe for concurrent use by multiple goroutines. The returned client must be Closed when it is done being used.

Using the Client

The following is an example of making an API call with the newly created client.

ctx := context.Background()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := spanner.NewClient(ctx)
if err != nil {
    // TODO: Handle error.
}
defer c.Close()

req := &spannerpb.CreateSessionRequest{
    // TODO: Fill request struct fields.
    // See https://pkg.go.dev/cloud.google.com/go/spanner/apiv1/spannerpb#CreateSessionRequest.
}
resp, err := c.CreateSession(ctx, req)
if err != nil {
    // TODO: Handle error.
}
// TODO: Use resp.
_ = resp

Use of Context

The ctx passed to NewClient is used for authentication requests and for creating the underlying connection, but is not used for subsequent calls. Individual methods on the client use the ctx given to them.

To close the open connection, use the Close() method.

Functions

func DatabasePath (deprecated)

func DatabasePath(project, instance, database string) string

DatabasePath returns the path for the database resource.

Deprecated: Use

fmt.Sprintf("projects/%s/instances/%s/databases/%s", project, instance, database)

instead.

func DefaultAuthScopes

func DefaultAuthScopes() []string

DefaultAuthScopes reports the default set of authentication scopes to use with this package.

func DefaultClientOptions

func DefaultClientOptions() []option.ClientOption

Returns the default client options used by the generated Spanner client.

This function is only intended for use by the client library, and may be removed at any time without any warning.

func SessionPath (deprecated)

func SessionPath(project, instance, database, session