gcsbucket

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2018 License: BSD-3-Clause Imports: 5 Imported by: 0

README

GoDoc Go Report Card

GCS Bucket

GCS Bucket is an implementation of Bucket with Google Cloud Storage.

Please refer to the FSDB project for more background information.

(Example code on godoc)

License

BSD License.

Documentation

Overview

Package gcsbucket provides an implementation of Bucket for Google Cloud Storage.

Example
package main

import (
	"context"
	"fmt"
	"io/ioutil"
	"log"
	"strings"

	"github.com/fishy/gcsbucket"
)

func main() {
	ctx := context.Background()
	bkt, err := gcsbucket.Open(ctx, "test-bucket")
	if err != nil {
		// TODO: error handling
	}

	obj := "test/object"
	content := `Lorem ipsum dolor sit amet,
consectetur adipiscing elit,
sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.

Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.

Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.

Excepteur sint occaecat cupidatat non proident,
sunt in culpa qui officia deserunt mollit anim id est laborum.`

	if err := bkt.Write(ctx, obj, strings.NewReader(content)); err != nil {
		log.Fatal(err)
	}
	reader, err := bkt.Read(ctx, obj)
	if err != nil {
		log.Fatal(err)
	}
	defer reader.Close()
	buf, err := ioutil.ReadAll(reader)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(string(buf)) // content
	if err := bkt.Delete(ctx, obj); err != nil {
		log.Fatal(err)
	}
	fmt.Println(bkt.IsNotExist(bkt.Delete(ctx, obj))) // true
}
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type GCSBucket

type GCSBucket struct {
	// contains filtered or unexported fields
}

GCSBucket is an implementation of bucket with Google Cloud Storage.

func Open

func Open(ctx context.Context, bucket string) (*GCSBucket, error)

Open opens a gcs bucket.

The bucket must already exist, otherwise all operations will fail.

func (*GCSBucket) Close

func (gcs *GCSBucket) Close() error

Close releases resources associated with this bucket.

All operations will panic after Close is called.

Close need not be called at program exit.

func (*GCSBucket) Delete

func (gcs *GCSBucket) Delete(ctx context.Context, name string) error

Delete deletes an object from the bucket.

func (*GCSBucket) IsNotExist

func (gcs *GCSBucket) IsNotExist(err error) bool

IsNotExist checks whether err is storage.ErrObjectNotExist.

func (*GCSBucket) Read

func (gcs *GCSBucket) Read(ctx context.Context, name string) (
	io.ReadCloser,
	error,
)

func (*GCSBucket) Write

func (gcs *GCSBucket) Write(
	ctx context.Context,
	name string,
	data io.Reader,
) error

Jump to

Keyboard shortcuts

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