s3

package
v0.0.0-...-bc49051 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2024 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ACLPrivate    = "private"
	ACLPublicRead = "public-read"
)

ACLs

Variables

View Source
var (
	KnownExtensions = map[string]string{
		".html": "text/html; charset=utf-8",
		".xml":  "text/xml; charset",
		".json": "application/json; charset=utf-8",
		".css":  "text/css; charset=utf-8",
		".js":   "application/javascript",
		".jpg":  "image/jpeg",
		".jpeg": "image/jpeg",
		".png":  "image/png",
	}
)

KnownExtenions are known extenions mapped to their content types.

Functions

func DetectContentType

func DetectContentType(path string) (string, error)

DetectContentType generates the content type of a given file by path.

func IsNotFound

func IsNotFound(err error) bool

IsNotFound returns if an error is a not found error.

Types

type File

type File struct {
	ETag                 string
	Contents             []byte
	ACL                  string
	FilePath             string
	Bucket               string
	Key                  string
	ContentType          string
	ContentDisposition   string
	ServerSideEncryption string
}

File is info for a file upload.

func (File) ACLOrDefault

func (f File) ACLOrDefault() string

ACLOrDefault returns the file ACL or a default.

func (File) IsZero

func (f File) IsZero() bool

IsZero returns if the file is set or not.

type Manager

type Manager struct {
	Log               *log.Logger
	Ignores           []string
	Config            aws.Config
	Session           *session.Session
	PutObjectDefaults File
	DryRun            bool
	Parallelism       int
}

Manager is a helper for uploading files to s3.

func New

func New(cfg aws.Config) *Manager

New returns a new manager.

func (Manager) Delete

func (m Manager) Delete(ctx context.Context, bucket, key string) error

Delete removes an object with a given key.

func (Manager) DiscoverFiles

func (m Manager) DiscoverFiles(ctx context.Context, directoryPath string) (localFiles []string, err error)

DiscoverFiles discovers local files.

func (Manager) GenerateETag

func (m Manager) GenerateETag(path string) (string, error)

GenerateETag generate an etag for a give file by path.

func (Manager) Get

func (m Manager) Get(ctx context.Context, bucket, key string) (file File, contents io.ReadCloser, err error)

Get fetches a file at a given key

func (Manager) GetKey

func (m Manager) GetKey(rootPath, workingPath string) string

GetKey returns the relative path for a given file.

func (Manager) GetMeta

func (m Manager) GetMeta(ctx context.Context, bucket, key string) (meta File, err error)

GetMeta fetches file metadata at a given key

func (Manager) List

func (m Manager) List(ctx context.Context, bucket string) ([]File, error)

List lists all files in a bucket.

func (Manager) ParallelismOrDefault

func (m Manager) ParallelismOrDefault() int

ParallelismOrDefault returns the parallelism or a default.

func (Manager) ProcessFiles

func (m Manager) ProcessFiles(ctx context.Context, localFiles []string, directoryPath, bucket string) (invalidated []string, err error)

ProcessFiles processes the files list.

func (Manager) Put

func (m Manager) Put(ctx context.Context, fileInfo File) error

Put uploads a file to s3.

func (Manager) SyncDirectory

func (m Manager) SyncDirectory(ctx context.Context, directoryPath, bucket string) (invalidations []string, err error)

SyncDirectory sync's a directory. It returns a list of invalidated keys (i.e. keys to update or remove), and an error.

type Set

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

Set is a set that can be accessed concurrently.

func (*Set) Has

func (s *Set) Has(value string) (has bool)

Has returns if a value is in the set

func (*Set) Set

func (s *Set) Set(value string)

Set adds a value

Jump to

Keyboard shortcuts

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