s3

package module
v0.0.0-...-7efb75f Latest Latest
Warning

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

Go to latest
Published: May 30, 2020 License: MIT Imports: 20 Imported by: 14

README

go-s3

A simple library for interfacing with Amazon S3 from Go.

Example

package main

import (
	"fmt"
	"io"
	"os"

	"github.com/jhunt/go-s3"
)

func main() {
	/* ... some setup ... */

	c, err := s3.NewClient(&s3.Client{
		AccessKeyID:     aki,
		SecretAccessKey: key,
		Region:          reg,
		Bucket:          bkt,
	})
	if err != nil {
		fmt.Fprintf(os.Stderr, "!!! unable to configure s3 client: %s\n", err)
		os.Exit(1)
	}

	u, err := c.NewUpload(path)
	if err != nil {
		fmt.Fprintf(os.Stderr, "!!! unable to start multipart upload: %s\n", err)
		os.Exit(1)
	}

	n, err := u.Stream(os.Stdin, 5*1024*1024*1024)
	if err != nil {
		fmt.Fprintf(os.Stderr, "!!! unable to stream <stdin> in 5m parts: %s\n", err)
		os.Exit(1)
	}

	err = u.Done()
	if err != nil {
		fmt.Fprintf(os.Stderr, "!!! unable to complete multipart upload: %s\n", err)
		os.Exit(1)
	}
}

Environment Variables

The following environment variables affect the behavior of this library:

  • $S3_TRACE - If set to "yes", "y", or "1" (case-insensitive), any and all HTTP(S) requests will be dumped to standard error. If set to the value "header" or "headers", only the headers of requests and responses will be dumped.

Documentation

Index

Constants

View Source
const (
	PrivateACL                = "private"
	PublicReadACL             = "public-read"
	PublicReadWriteACL        = "public-read-write"
	AWSExecReadACL            = "aws-exec-read"
	AuthenticatedReadACL      = "authenticated-read"
	BucketOwnerReadACL        = "bucket-owner-read"
	BucketOwnerFullControlACL = "bucket-owner-full-control"
	LogDeliveryWriteACL       = "log-delivery-write"
)
View Source
const EveryoneURI = "http://acs.amazonaws.com/groups/global/AllUsers"

Variables

This section is empty.

Functions

func ResponseError

func ResponseError(res *http.Response) error

func ResponseErrorFrom

func ResponseErrorFrom(b []byte) error

Types

type ACL

type ACL []Grant

type Bucket

type Bucket struct {
	Name         string
	CreationDate time.Time
	OwnerID      string
	OwnerName    string
}

type Bytes

type Bytes int64

func (Bytes) Bytes

func (b Bytes) Bytes() string

func (Bytes) Exabytes

func (b Bytes) Exabytes() string

func (Bytes) Gigabytes

func (b Bytes) Gigabytes() string

func (Bytes) Kilobytes

func (b Bytes) Kilobytes() string

func (Bytes) Megabytes

func (b Bytes) Megabytes() string

func (Bytes) Petabytes

func (b Bytes) Petabytes() string

func (Bytes) String

func (b Bytes) String() string

func (Bytes) Terabytes

func (b Bytes) Terabytes() string

type Client

type Client struct {
	AccessKeyID     string
	SecretAccessKey string
	Token           string
	Region          string
	Bucket          string
	Domain          string
	Protocol        string
	SOCKS5Proxy     string

	SignatureVersion int

	CACertificates     []string
	SkipSystemCAs      bool
	InsecureSkipVerify bool

	UsePathBuckets bool
	// contains filtered or unexported fields
}

func NewClient

func NewClient(c *Client) (*Client, error)

func (*Client) ChangeACL

func (c *Client) ChangeACL(path, acl string) error

func (*Client) CreateBucket

func (c *Client) CreateBucket(name, region, acl string) error

func (*Client) Delete

func (c *Client) Delete(path string) error

func (*Client) DeleteBucket

func (c *Client) DeleteBucket(name string) error

func (*Client) Get

func (c *Client) Get(key string) (io.Reader, error)

func (*Client) GetACL

func (c *Client) GetACL(key string) (ACL, error)

func (*Client) List

func (c *Client) List() ([]Object, error)

func (*Client) ListBuckets

func (c *Client) ListBuckets() ([]Bucket, error)

func (*Client) NewUpload

func (c *Client) NewUpload(path string, headers *http.Header) (*Upload, error)

func (*Client) Trace

func (c *Client) Trace(out io.Writer, yes, body bool)

type Grant

type Grant struct {
	GranteeID   string
	GranteeName string
	Group       string
	Permission  string
}

type Object

type Object struct {
	Key          string
	LastModified time.Time
	ETag         string
	Size         Bytes
	StorageClass string
	OwnerID      string
	OwnerName    string
}

type Upload

type Upload struct {
	Key string
	// contains filtered or unexported fields
}

func (*Upload) Done

func (u *Upload) Done() error

func (*Upload) ParallelStream

func (u *Upload) ParallelStream(in io.Reader, block int, threads int) (int64, error)

func (*Upload) Stream

func (u *Upload) Stream(in io.Reader, block int) (int64, error)

func (*Upload) Write

func (u *Upload) Write(b []byte) error

Directories

Path Synopsis
examples
s3

Jump to

Keyboard shortcuts

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