package storage
import "cloud.google.com/go/storage/internal/apiv2"
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 ¶
- func DefaultAuthScopes() []string
- type CallOptions
- type Client
- func NewClient(ctx context.Context, opts ...option.ClientOption) (*Client, error)
- func (c *Client) Close() error
- func (c *Client) Connection() *grpc.ClientConn
- func (c *Client) QueryWriteStatus(ctx context.Context, req *storagepb.QueryWriteStatusRequest, opts ...gax.CallOption) (*storagepb.QueryWriteStatusResponse, error)
- func (c *Client) ReadObject(ctx context.Context, req *storagepb.ReadObjectRequest, opts ...gax.CallOption) (storagepb.Storage_ReadObjectClient, error)
- func (c *Client) StartResumableWrite(ctx context.Context, req *storagepb.StartResumableWriteRequest, opts ...gax.CallOption) (*storagepb.StartResumableWriteResponse, error)
- func (c *Client) WriteObject(ctx context.Context, opts ...gax.CallOption) (storagepb.Storage_WriteObjectClient, error)
Examples ¶
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 ¶
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.
func (*Client) Close ¶
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 ¶
func (c *Client) QueryWriteStatus(ctx context.Context, req *storagepb.QueryWriteStatusRequest, opts ...gax.CallOption) (*storagepb.QueryWriteStatusResponse, error)
QueryWriteStatus determines the committed_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 committed_size values will be
non-decreasing.
Code:play
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
}
func (*Client) ReadObject ¶
func (c *Client) ReadObject(ctx context.Context, req *storagepb.ReadObjectRequest, opts ...gax.CallOption) (storagepb.Storage_ReadObjectClient, error)
ReadObject reads an object’s data.
func (*Client) StartResumableWrite ¶
func (c *Client) StartResumableWrite(ctx context.Context, req *storagepb.StartResumableWriteRequest, opts ...gax.CallOption) (*storagepb.StartResumableWriteResponse, error)
StartResumableWrite starts a resumable write. How long the write operation remains valid, and
what happens when the write operation becomes invalid, are
service-dependent.
Code:play
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
}
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 committed_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.
Source Files ¶
doc.go storage_client.go
- Version
- v1.16.1
- Published
- Aug 31, 2021
- Platform
- linux/amd64
- Imports
- 16 packages
- Last checked
- 2 hours ago –
Tools for package owners.