s3

package module
v0.0.0-...-2fc7d40 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2020 License: MIT Imports: 18 Imported by: 0

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) Head

func (c *Client) Head(key string) (*Object, error)

func (*Client) List

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

func (*Client) ListBuckets

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

func (*Client) ListIter

func (c *Client) ListIter(prefix string) *ListIter

func (*Client) NewUpload

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

func (*Client) Put

func (c *Client) Put(key string, body []byte, hdr *http.Header) error

type Error

type Error struct {
	Code    string `xml:"Code"`
	Message string `xml:"Message"`
}

func (Error) Error

func (e Error) Error() string

type Grant

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

type ListIter

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

func (*ListIter) Next

func (li *ListIter) Next() (*Object, error)

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

Jump to

Keyboard shortcuts

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