s3bucket

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: 10 Imported by: 0

README

GoDoc Go Report Card

S3 Bucket

S3 Bucket is an implementation of Bucket with AWS S3.

Please refer to the FSDB project for more background information.

(Example code on godoc)

License

BSD License.

Documentation

Overview

Package s3bucket provides an implementation of Bucket for AWS S3.

Example
package main

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

	"github.com/fishy/s3bucket"
)

func main() {
	ctx := context.Background()
	region := "us-east-1"
	bkt := s3bucket.Open("test-bucket", region)

	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.`

	_, err := bkt.Read(ctx, obj)
	fmt.Println(bkt.IsNotExist(err)) // true

	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)
	}
}
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type S3Bucket

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

S3Bucket is an implementation of bucket with S3.

func Open

func Open(bucket string, region string) *S3Bucket

Open opens an s3 bucket.

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

func (*S3Bucket) Delete

func (bkt *S3Bucket) Delete(ctx context.Context, name string) error

Delete deletes an object from the bucket.

Please note that S3 will NOT return error when deleting a non-exist object.

func (*S3Bucket) IsNotExist

func (bkt *S3Bucket) IsNotExist(err error) bool

IsNotExist checks whether err is an awserr.Error with code ErrCodeNoSuchKey.

func (*S3Bucket) Read

func (bkt *S3Bucket) Read(ctx context.Context, name string) (
	io.ReadCloser,
	error,
)

func (*S3Bucket) Write

func (bkt *S3Bucket) 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