storage

package
v0.6.17 Latest Latest
Warning

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

Go to latest
Published: Jan 26, 2025 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package storage provides basic storage interfaces for storage providers to write / read objects to and from

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidS3Bucket is returned when an invalid s3 bucket is provided
	ErrInvalidS3Bucket = errors.New("invalid s3 bucket provided")
	// ErrInvalidFolderPath is returned when an invalid folder path is provided
	ErrInvalidFolderPath = errors.New("invalid folder path provided")
	// ErrMissingRequiredAWSParams is returned when required AWS parameters are missing
	ErrMissingRequiredAWSParams = errors.New("missing required AWS parameters")
)
View Source
var ProviderDisk = "disk"

ProviderDisk is the provider for the disk storage

View Source
var ProviderS3 = "s3"

ProviderS3 is the provider for the S3 storage

Functions

This section is empty.

Types

type Disk

type Disk struct {

	// Scheme is the scheme of the storage backend
	Scheme string
	// Opts is the options for the disk storage
	Opts *DiskOptions
	// contains filtered or unexported fields
}

func NewDiskStorage

func NewDiskStorage(opts *DiskOptions) (*Disk, error)

func (*Disk) Close

func (d *Disk) Close() error

func (*Disk) Download

Download is used to download a file from the storage backend

func (*Disk) GetPresignedURL

func (d *Disk) GetPresignedURL(ctx context.Context, key string, expires time.Duration) (string, error)

GetPresignedURL is used to get a presigned URL for a file in the storage backend TODO: Implement this method

func (*Disk) GetScheme

func (d *Disk) GetScheme() *string

GetScheme returns the scheme of the storage backend

func (*Disk) ListBuckets added in v0.3.1

func (d *Disk) ListBuckets() ([]string, error)

ListBuckets lists the local bucket if it exists

func (*Disk) ManagerUpload

func (d *Disk) ManagerUpload(ctx context.Context, files [][]byte) error

ManagerUpload uploads multiple files to disk TODO: Implement this method

func (*Disk) Upload

type DiskOption added in v0.3.1

type DiskOption func(*DiskOptions)

func WithLocalBucket added in v0.3.1

func WithLocalBucket(bucket string) DiskOption

WithLocalBucket is a DiskOption that sets the bucket for the disk storage which equates to a folder on the file system

func WithLocalKey added in v0.3.1

func WithLocalKey(key string) DiskOption

WithLocalKey specifies the name of the file in the local folder

func WithLocalURL added in v0.6.10

func WithLocalURL(url string) DiskOption

type DiskOptions added in v0.3.1

type DiskOptions struct {
	Bucket string
	Key    string
	// LocalURL is the URL to use for the "presigned" URL for the file
	// e.g for local development, this can be http://localhost:17608/files/
	LocalURL string
}

func NewDiskOptions added in v0.3.1

func NewDiskOptions(opts ...DiskOption) *DiskOptions

NewDiskOptions returns a new DiskOptions struct

type S3Option added in v0.3.1

type S3Option func(*S3Options)

S3Option is a function that modifies S3Options

func WithAWSConfig added in v0.3.1

func WithAWSConfig(cfg aws.Config) S3Option

WithAWSConfig sets the AWS configuration for S3Options

func WithAccessKeyID added in v0.3.1

func WithAccessKeyID(accessKeyID string) S3Option

WithAccessKeyID sets the access key ID for S3Options

func WithBucket added in v0.3.1

func WithBucket(bucket string) S3Option

WithBucket sets the bucket for S3Options

func WithEndpoint added in v0.3.1

func WithEndpoint(endpoint string) S3Option

WithEndpoint sets the endpoint for S3Options

func WithPresignedURLTimeout added in v0.3.1

func WithPresignedURLTimeout(timeout int) S3Option

WithPresignedURLTimeout sets the presigned URL timeout for S3Options

func WithRegion added in v0.3.1

func WithRegion(region string) S3Option

WithRegion sets the region for S3Options

func WithSecretAccessKey added in v0.3.1

func WithSecretAccessKey(secretAccessKey string) S3Option

WithSecretAccessKey sets the secret access key for S3Options

func WithUseSSL added in v0.3.1

func WithUseSSL(useSSL bool) S3Option

WithUseSSL sets the use SSL flag for S3Options

type S3Options

type S3Options struct {
	// Bucket to store objects in
	Bucket string
	// DebugMode will log all requests and responses
	DebugMode bool
	// UsePathStyle allows you to enable the client to use path-style addressing, i.e., https://s3.amazonaws.com/BUCKET/KEY .
	// by default, the S3 client will use virtual hosted bucket addressing when possible( https://BUCKET.s3.amazonaws.com/KEY ).
	UsePathStyle bool
	// ACL should only be used if the bucket supports ACL
	ACL types.ObjectCannedACL
	// Region is the region to use for the S3 client
	Region string
	// AccessKeyID is the access key ID to use for the S3 client
	AccessKeyID string
	// SecretAccessKey is the secret access key to use for the S3 client
	SecretAccessKey string
	// Endpoint is the endpoint to use for the S3 client
	Endpoint string
	// UseSSL is a flag to determine if the S3 client should use SSL
	UseSSL bool
	// PresignURLTimeout is the timeout for presigned URLs
	PresignedURLTimeout int
	// AWSConfig is the AWS configuration to use for the S3 client
	AWSConfig aws.Config
}

S3Options is used to configure the S3Store

func NewS3Options added in v0.3.1

func NewS3Options(opts ...S3Option) *S3Options

NewS3Options creates a new S3Options instance with the provided options

type S3Store

type S3Store struct {
	Client             *s3.Client
	Opts               *S3Options
	PresignClient      *s3.PresignClient
	Downloader         *manager.Downloader
	Uploader           *manager.Uploader
	ObjExistsWaiter    *s3.ObjectExistsWaiter
	ObjNotExistsWaiter *s3.ObjectNotExistsWaiter
	Scheme             string
}

S3Store is a store that uses S3 as the backend

func NewS3FromConfig

func NewS3FromConfig(opts *S3Options) (*S3Store, error)

NewS3FromConfig creates a new S3Store from the provided configuration

func (*S3Store) Close

func (s *S3Store) Close() error

Close the S3Store satisfying the Storage interface

func (*S3Store) Delete added in v0.3.1

func (s *S3Store) Delete(ctx context.Context, key string) error

Delete an object from S3

func (*S3Store) Download

Download an object from S3 and return the metadata and a reader - the reader must be closed after use and is the responsibility of the caller

func (*S3Store) Exists

func (s *S3Store) Exists(ctx context.Context, key string) (bool, error)

Exists checks if an object exists in S3

func (*S3Store) GetPresignedURL

func (s *S3Store) GetPresignedURL(ctx context.Context, key string, expires time.Duration) (string, error)

GetPresignedURL returns a URL that provides access to a file for the set duration if no duration is provided, it will default to 15 minutes

func (*S3Store) GetScheme

func (s *S3Store) GetScheme() *string

GetScheme returns the scheme of the storage backend

func (*S3Store) GetTags added in v0.3.1

func (s *S3Store) GetTags(ctx context.Context, key string) (map[string]string, error)

GetTags returns the tags for an object in a bucket

func (*S3Store) HeadObj added in v0.3.1

func (s *S3Store) HeadObj(ctx context.Context, key string) (*s3.HeadObjectOutput, error)

HeadObj checks if an object exists in S3

func (*S3Store) ListBuckets added in v0.3.1

func (s *S3Store) ListBuckets() ([]string, error)

ListBuckets lists the buckets in the current account.

func (*S3Store) ManagerUpload

func (s *S3Store) ManagerUpload(ctx context.Context, files [][]byte) error

ManagerUpload uploads multiple files to S3

func (*S3Store) Tag added in v0.3.1

func (s *S3Store) Tag(ctx context.Context, key string, tags map[string]string) error

Tag updates an existing object in a bucket with specific tags

func (*S3Store) Upload

Upload an object to S3 and return the metadata

Jump to

Keyboard shortcuts

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