gcsblob

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2018 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package gcsblob provides a blob implementation that uses GCS. Use OpenBucket to construct a blob.Bucket.

Open URLs

For blob.Open URLs, gcsblob registers for the scheme "gs"; URLs start with "gs://".

The URL's Host is used as the bucket name. The following query options are supported:

  • cred_path: Sets path to the Google credentials file. If unset, default credentials are loaded. See https://cloud.google.com/docs/authentication/production.
  • access_id: Sets Options.GoogleAccessID.
  • private_key_path: Sets path to a private key, which is read and used to set Options.PrivateKey.

Example URL:

gs://mybucket

As

gcsblob exposes the following types for As:

  • Bucket: *storage.Client
  • Error: *googleapi.Error
  • ListObject: storage.ObjectAttrs
  • ListOptions.BeforeList: *storage.Query
  • Reader: storage.Reader
  • Attributes: storage.ObjectAttrs
  • WriterOptions.BeforeWrite: *storage.Writer
Example
package main

import (
	"context"

	"github.com/google/go-cloud/blob/gcsblob"
	"github.com/google/go-cloud/gcp"
)

func main() {
	ctx := context.Background()

	// Load credentials for GCP.
	// This example uses the default approach; see
	// https://cloud.google.com/docs/authentication/production
	// for more info on alternatives.
	creds, err := gcp.DefaultCredentials(ctx)
	if err != nil {
		return
	}

	// Create an HTTP client.
	// This example uses the default HTTP transport and the credentials created
	// above.
	client, err := gcp.NewHTTPClient(gcp.DefaultTransport(), gcp.CredentialsTokenSource(creds))
	if err != nil {
		return
	}

	// Create a *blob.Bucket.
	_, _ = gcsblob.OpenBucket(ctx, "my-bucket", client, nil)

}
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func OpenBucket

func OpenBucket(ctx context.Context, bucketName string, client *gcp.HTTPClient, opts *Options) (*blob.Bucket, error)

OpenBucket returns a *blob.Bucket backed by GCS. See the package documentation for an example.

Types

type Options added in v0.7.0

type Options struct {
	// GoogleAccessID represents the authorizer for SignedURL.
	// Required to use SignedURL.
	// See https://godoc.org/cloud.google.com/go/storage#SignedURLOptions.
	GoogleAccessID string

	// PrivateKey is the Google service account private key.
	// Exactly one of PrivateKey or SignBytes must be non-nil to use SignedURL.
	// See https://godoc.org/cloud.google.com/go/storage#SignedURLOptions.
	PrivateKey []byte

	// SignBytes is a function for implementing custom signing.
	// Exactly one of PrivateKey or SignBytes must be non-nil to use SignedURL.
	// See https://godoc.org/cloud.google.com/go/storage#SignedURLOptions.
	SignBytes func([]byte) ([]byte, error)
}

Options sets options for constructing a *blob.Bucket backed by GCS.

Jump to

Keyboard shortcuts

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