storage

package
v0.1.4-alpha Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2020 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewAwsSessionFromEnv

func NewAwsSessionFromEnv() (*session.Session, error)

NewAwsSessionFromEnv creates a new aws session from environment variables.

Types

type FileNameStrategy

type FileNameStrategy func(basename string) string

FileNameStrategy is a callable used for naming a file.

func Crc32TimeNamingStrategy

func Crc32TimeNamingStrategy() FileNameStrategy

Crc32TimeNamingStrategy returns the crc32 encoded string of the unix time in nanoseconds plus the file extension of the given basename.

type HTTPClient

type HTTPClient interface {
	Get(url string) (resp *http.Response, err error)
}

HTTPClient is the interface for interacting with http calls.

type S3Client

type S3Client interface {
	GetObject(input *s3.GetObjectInput) (*s3.GetObjectOutput, error)
	PutObject(input *s3.PutObjectInput) (*s3.PutObjectOutput, error)
}

S3Client is the interface for interacting with S3-related stuff.

type S3Downloader

type S3Downloader interface {
	Download(w io.WriterAt, input *s3.GetObjectInput, options ...func(*s3manager.Downloader)) (n int64, err error)
}

S3Downloader downloads files from s3.

type S3Storage

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

S3Storage is the Storage implementation for AWS S3.

func NewS3Storage

func NewS3Storage(httpClient HTTPClient, s3 S3Client, s3Downloader S3Downloader, bucket string, opts ...S3StorageOption) *S3Storage

NewS3Storage creates a new S3 storage implementation from params.

func NewS3StorageFromEnv

func NewS3StorageFromEnv() (*S3Storage, error)

NewS3StorageFromEnv creates the new S3 storage implementation from env vars.

func (*S3Storage) Download

func (storage *S3Storage) Download(key string) (*bytes.Reader, error)

Download downloads the specified key and returns the bytes.

func (*S3Storage) UploadBytes

func (storage *S3Storage) UploadBytes(b *bytes.Buffer, remotePathName string) error

UploadBytes uploads an item as bytes with the specified name.

func (*S3Storage) UploadFromRemote

func (storage *S3Storage) UploadFromRemote(remoteFile string, remoteDir string) (UploadedImage, error)

UploadFromRemote uploads a file from a remote url. The remote file gets temporarily read in memory.

type S3StorageOption

type S3StorageOption func(*S3Storage)

S3StorageOption sets optional parameters.

func NamingStrategy

func NamingStrategy(strategy FileNameStrategy) S3StorageOption

NamingStrategy sets the naming strategy for the storage.

type Storage

type Storage interface {
	Download(key string) (*bytes.Reader, error)
	UploadFromRemote(remoteURL string, remoteDir string) (UploadedImage, error)
	UploadBytes(b *bytes.Buffer, remotePathName string) error
}

Storage defines the interface for uploading remote files to a remote directory.

type UploadedImage

type UploadedImage struct {
	Pathname string
	MD5Hash  string
}

UploadedImage is the uploaded image with its pathname and md5 hash of the image data.

Jump to

Keyboard shortcuts

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