storage

package
v1.53.2 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2024 License: AGPL-3.0, AGPL-3.0-or-later Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type S3Client

type S3Client interface {
	HeadBucketWithContext(ctx context.Context, input *s3.HeadBucketInput, opts ...request.Option) (*s3.HeadBucketOutput, error)
	GetObjectWithContext(ctx context.Context, input *s3.GetObjectInput, opts ...request.Option) (*s3.GetObjectOutput, error)
	PutObjectWithContext(ctx context.Context, input *s3.PutObjectInput, opts ...request.Option) (*s3.PutObjectOutput, error)
}

S3Client provides a mockable subset of the S3 API

func NewS3Client

func NewS3Client(opts *S3Options) (S3Client, error)

NewS3Client creates a new S3 client

type S3Options

type S3Options struct {
	AWSAccessKeyID     string
	AWSSecretAccessKey string
	Endpoint           string
	Region             string
	DisableSSL         bool
	ForcePathStyle     bool
	MaxRetries         int
}

S3Options are options for an S3 client

type Storage

type Storage interface {
	// Name is the name of the storage implementation
	Name() string

	// Test verifies this storage is functioning and returns an error if not
	Test(ctx context.Context) error

	// Get retrieves the file from the given path
	Get(ctx context.Context, path string) (string, []byte, error)

	// Put stores the given file at the given path
	Put(ctx context.Context, path string, contentType string, body []byte) (string, error)

	// BatchPut stores the given uploads, returning the URLs of the files after upload
	BatchPut(ctx context.Context, uploads []*Upload) error
}

Storage is an interface that provides storing and retrieval of file like things

func NewFS

func NewFS(directory string, perms os.FileMode) Storage

NewFS creates a new file system storage service suitable for use in tests

func NewS3

func NewS3(client S3Client, bucket, region, acl string, workersPerBatch int) Storage

NewS3 creates a new S3 storage service. Callers can specify how many parallel uploads will take place at once when calling BatchPut with workersPerBatch

type Upload added in v1.10.0

type Upload struct {
	Path        string
	ContentType string
	Body        []byte

	// set by BatchPut
	URL   string
	Error error
}

Upload is our type for a file in a batch upload

Jump to

Keyboard shortcuts

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