storage

package
v1.18.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 18, 2021 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package storage is an auto-generated package for the Cloud Storage API.

Lets you store and retrieve potentially-large, immutable data objects.

NOTE: This package is in alpha. It is not stable, and is likely to change.

Example usage

To get started with this package, create a client.

ctx := context.Background()
c, err := storage.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.

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.

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

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultAuthScopes

func DefaultAuthScopes() []string

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

Types

type CallOptions

type CallOptions struct {
	ReadObject          []gax.CallOption
	WriteObject         []gax.CallOption
	StartResumableWrite []gax.CallOption
	QueryWriteStatus    []gax.CallOption
}

CallOptions contains the retry settings for each method of Client.

type Client

type Client struct {

	// The call options for this service.
	CallOptions *CallOptions
	// contains filtered or unexported fields
}

Client is a client for interacting with Cloud Storage API. Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.

Manages Google Cloud Storage resources.

func NewClient

func NewClient(ctx context.Context, opts ...option.ClientOption) (*Client, error)

NewClient creates a new storage client based on gRPC. The returned client must be Closed when it is done being used to clean up its underlying connections.

Manages Google Cloud Storage resources.

Example
package main

import (
	"context"

	storage "cloud.google.com/go/storage/internal/apiv2"
)

func main() {
	ctx := context.Background()
	c, err := storage.NewClient(ctx)
	if err != nil {
		// TODO: Handle error.
	}
	defer c.Close()

	// TODO: Use client.
	_ = c
}
Output:

func (*Client) Close

func (c *Client) Close() error

Close closes the connection to the API service. The user should invoke this when the client is no longer required.

func (*Client) Connection

func (c *Client) Connection() *grpc.ClientConn

Connection returns a connection to the API service.

Deprecated.

func (*Client) QueryWriteStatus

QueryWriteStatus determines the persisted_size for an object that is being written, which can then be used as the write_offset for the next Write() call.

If the object does not exist (i.e., the object has been deleted, or the first Write() has not yet reached the service), this method returns the error NOT_FOUND.

The client may call QueryWriteStatus() at any time to determine how much data has been processed for this object. This is useful if the client is buffering data and needs to know which data can be safely evicted. For any sequence of QueryWriteStatus() calls for a given object name, the sequence of returned persisted_size values will be non-decreasing.

Example
package main

import (
	"context"

	storage "cloud.google.com/go/storage/internal/apiv2"
	storagepb "google.golang.org/genproto/googleapis/storage/v2"
)

func main() {
	ctx := context.Background()
	c, err := storage.NewClient(ctx)
	if err != nil {
		// TODO: Handle error.
	}
	defer c.Close()

	req := &storagepb.QueryWriteStatusRequest{
		// TODO: Fill request struct fields.
		// See https://pkg.go.dev/google.golang.org/genproto/googleapis/storage/v2#QueryWriteStatusRequest.
	}
	resp, err := c.QueryWriteStatus(ctx, req)
	if err != nil {
		// TODO: Handle error.
	}
	// TODO: Use resp.
	_ = resp
}
Output:

func (*Client) ReadObject

ReadObject reads an object’s data.

func (*Client) StartResumableWrite

StartResumableWrite starts a resumable write. How long the write operation remains valid, and what happens when the write operation becomes invalid, are service-dependent.

Example
package main

import (
	"context"

	storage "cloud.google.com/go/storage/internal/apiv2"
	storagepb "google.golang.org/genproto/googleapis/storage/v2"
)

func main() {
	ctx := context.Background()
	c, err := storage.NewClient(ctx)
	if err != nil {
		// TODO: Handle error.
	}
	defer c.Close()

	req := &storagepb.StartResumableWriteRequest{
		// TODO: Fill request struct fields.
		// See https://pkg.go.dev/google.golang.org/genproto/googleapis/storage/v2#StartResumableWriteRequest.
	}
	resp, err := c.StartResumableWrite(ctx, req)
	if err != nil {
		// TODO: Handle error.
	}
	// TODO: Use resp.
	_ = resp
}
Output:

func (*Client) WriteObject

func (c *Client) WriteObject(ctx context.Context, opts ...gax.CallOption) (storagepb.Storage_WriteObjectClient, error)

WriteObject stores a new object and metadata.

An object can be written either in a single message stream or in a resumable sequence of message streams. To write using a single stream, the client should include in the first message of the stream an WriteObjectSpec describing the destination bucket, object, and any preconditions. Additionally, the final message must set ‘finish_write’ to true, or else it is an error.

For a resumable write, the client should instead call StartResumableWrite() and provide that method an WriteObjectSpec. They should then attach the returned upload_id to the first message of each following call to Create. If there is an error or the connection is broken during the resumable Create(), the client should check the status of the Create() by calling QueryWriteStatus() and continue writing from the returned persisted_size. This may be less than the amount of data the client previously sent.

The service will not view the object as complete until the client has sent a WriteObjectRequest with finish_write set to true. Sending any requests on a stream after sending a request with finish_write set to true will cause an error. The client should check the response it receives to determine how much data the service was able to commit and whether the service views the object as complete.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL