storage

package
v1.16.0 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2022 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CloseCheck

func CloseCheck(f func() error)

Types

type LocalStorage

type LocalStorage struct {
	Storage
	// contains filtered or unexported fields
}

LocalStorage is a local storage

func NewLocalStorage

func NewLocalStorage(basedir string, logger *log.Logger) (*LocalStorage, error)

NewLocalStorage is the factory for LocalStorage

func (*LocalStorage) Delete

func (s *LocalStorage) Delete(_ context.Context, token string, filename string) (err error)

Delete removes a file from storage

func (*LocalStorage) Get

func (s *LocalStorage) Get(_ context.Context, token string, filename string) (reader io.ReadCloser, contentLength uint64, err error)

Get retrieves a file from storage

func (*LocalStorage) Head

func (s *LocalStorage) Head(_ context.Context, token string, filename string) (contentLength uint64, err error)

Head retrieves content length of a file from storage

func (*LocalStorage) IsNotExist

func (s *LocalStorage) IsNotExist(err error) bool

IsNotExist indicates if a file doesn't exist on storage

func (*LocalStorage) Purge

func (s *LocalStorage) Purge(_ context.Context, days time.Duration) (err error)

Purge cleans up the storage

func (*LocalStorage) Put

func (s *LocalStorage) Put(_ context.Context, token string, filename string, reader io.Reader, contentType string, contentLength uint64) error

Put saves a file on storage

func (*LocalStorage) Type

func (s *LocalStorage) Type() string

Type returns the storage type

type S3Storage

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

S3Storage is a storage backed by AWS S3

func NewS3Storage

func NewS3Storage(accessKey, secretKey, bucketName string, purgeDays int, region, endpoint string, disableMultipart bool, forcePathStyle bool, logger *log.Logger) (*S3Storage, error)

NewS3Storage is the factory for S3Storage

func (*S3Storage) Delete

func (s *S3Storage) Delete(ctx context.Context, token string, filename string) (err error)

Delete removes a file from storage

func (*S3Storage) Get

func (s *S3Storage) Get(ctx context.Context, token string, filename string) (reader io.ReadCloser, contentLength uint64, err error)

Get retrieves a file from storage

func (*S3Storage) Head

func (s *S3Storage) Head(ctx context.Context, token string, filename string) (contentLength uint64, err error)

Head retrieves content length of a file from storage

func (*S3Storage) IsNotExist

func (s *S3Storage) IsNotExist(err error) bool

IsNotExist indicates if a file doesn't exist on storage

func (*S3Storage) Purge

func (s *S3Storage) Purge(context.Context, time.Duration) (err error)

Purge cleans up the storage

func (*S3Storage) Put

func (s *S3Storage) Put(ctx context.Context, token string, filename string, reader io.Reader, contentType string, _ uint64) (err error)

Put saves a file on storage

func (*S3Storage) Type

func (s *S3Storage) Type() string

Type returns the storage type

type Storage

type Storage interface {
	// Get retrieves a file from storage
	Get(ctx context.Context, token string, filename string) (reader io.ReadCloser, contentLength uint64, err error)
	// Head retrieves content length of a file from storage
	Head(ctx context.Context, token string, filename string) (contentLength uint64, err error)
	// Put saves a file on storage
	Put(ctx context.Context, token string, filename string, reader io.Reader, contentType string, contentLength uint64) error
	// Delete removes a file from storage
	Delete(ctx context.Context, token string, filename string) error
	// IsNotExist indicates if a file doesn't exist on storage
	IsNotExist(err error) bool
	// Purge cleans up the storage
	Purge(ctx context.Context, days time.Duration) error

	// Type returns the storage type
	Type() string
}

Storage is the interface for storage operation

Jump to

Keyboard shortcuts

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