Documentation
¶
Overview ¶
Package gcsx contains utilities for working with Google Cloud Storage (GCS).
Example ¶
package main
import (
"context"
"time"
"cloud.google.com/go/storage"
"github.com/apache/beam/sdks/go/pkg/beam/util/gcsx"
)
func main() {
ctx := context.Background()
c, err := gcsx.NewClient(ctx, storage.ScopeReadOnly)
if err != nil {
// do something
}
buckets, object, err := gcsx.ParseObject("gs://some-bucket/some-object")
if err != nil {
// do something
}
ctx, cancel := context.WithTimeout(ctx, 30*time.Second)
defer cancel()
bytes, err := gcsx.ReadObject(ctx, c, buckets, object)
if err != nil {
// do something
}
_ = bytes
}
Index ¶
- func BucketExists(ctx context.Context, client *storage.Client, bucket string) (bool, error)
- func CreateBucket(ctx context.Context, client *storage.Client, project, bucket string) error
- func Join(object string, elms ...string) string
- func MakeObject(bucket, path string) string
- func NewClient(ctx context.Context, scope string) (*storage.Client, error)
- func NewUnauthenticatedClient(ctx context.Context) (*storage.Client, error)
- func ParseObject(object string) (bucket, path string, err error)
- func ReadObject(ctx context.Context, client *storage.Client, bucket, object string) ([]byte, error)
- func Upload(ctx context.Context, client *storage.Client, project, bucket, object string, ...) (string, error)
- func WriteObject(ctx context.Context, client *storage.Client, bucket, object string, ...) error
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BucketExists ¶
BucketExists returns true iff the given bucket exists.
func CreateBucket ¶
CreateBucket creates a bucket in GCS.
func MakeObject ¶
MakeObject creates a object location from bucket and path. For example, MakeObject("foo", "bar/baz") returns "gs://foo/bar/baz". The bucket must be non-empty.
func NewClient ¶
NewClient creates a new GCS client with default application credentials, and supplied OAuth scope. The OAuth scopes are defined in https://godoc.org/cloud.google.com/go/storage#pkg-constants.
func NewUnauthenticatedClient ¶
NewUnauthenticatedClient creates a new GCS client without authentication.
func ParseObject ¶
ParseObject deconstructs a GCS object name into (bucket, name).
func ReadObject ¶
ReadObject reads the content of the given object in full.
Types ¶
This section is empty.