storage

package
v0.0.0-...-c407d37 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2024 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ComputeChecksum

func ComputeChecksum(data io.ReadSeeker) (string, error)

ComputeChecksum calculates the MD5 checksum for the provided data. It expects that the passed io object will be seeked to its beginning and will seek back to the beginning after reading its content.

func DetectContentType

func DetectContentType(data io.ReadSeeker) (string, error)

DetectContentType leverages http.DetectContentType to identify the content type of the provided data. It expects that the passed io object will be seeked to its beginning and will seek back to the beginning after reading its content.

func NewFilesystemHandler

func NewFilesystemHandler(fs afero.Fs, root string) http.HandlerFunc

NewFilesystemHandler returns an Handler that adds a Content-Type header so that files are handled properly by the browser.

func NewMemoryHandler

func NewMemoryHandler(root string) http.HandlerFunc

NewMemoryHandler returns an Handler that adds a Content-Type header so that files are handled properly by the browser.

Types

type FileStorer

type FileStorer interface {
	Store(string, io.ReadSeeker, string, *string) (*StoreResult, error)
	Fetch(string) (io.ReadCloser, error)
	Delete(string) error
	PresignedURL(string, string) (string, error)
	FileSystem() *afero.Afero
	TempFileSystem() *afero.Afero
	Tags(string) (map[string]string, error)
}

FileStorer is the set of methods needed to store and retrieve objects.

func InitStorage

func InitStorage(v *viper.Viper, logger *zap.Logger) FileStorer

InitStorage initializes the storage backend

type Filesystem

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

Filesystem is a storage backend that uses the local filesystem. It is intended only for use in development to avoid dependency on an external service.

func NewFilesystem

func NewFilesystem(params FilesystemParams) *Filesystem

NewFilesystem creates a new Filesystem struct using the provided FilesystemParams

func (*Filesystem) Delete

func (fs *Filesystem) Delete(key string) error

Delete deletes the file at the specified key

func (*Filesystem) Fetch

func (fs *Filesystem) Fetch(key string) (io.ReadCloser, error)

Fetch retrieves a copy of a file and stores it in a tempfile. The path to this file is returned.

It is the caller's responsibility to delete the tempfile.

func (*Filesystem) FileSystem

func (fs *Filesystem) FileSystem() *afero.Afero

FileSystem returns the underlying afero filesystem

func (*Filesystem) PresignedURL

func (fs *Filesystem) PresignedURL(key, contentType string) (string, error)

PresignedURL returns a URL that provides access to a file for 15 mintes.

func (*Filesystem) Store

func (fs *Filesystem) Store(key string, data io.ReadSeeker, _ string, _ *string) (*StoreResult, error)

Store stores the content from an io.ReadSeeker at the specified key.

func (*Filesystem) Tags

func (fs *Filesystem) Tags(_ string) (map[string]string, error)

Tags returns the tags for a specified key

func (*Filesystem) TempFileSystem

func (fs *Filesystem) TempFileSystem() *afero.Afero

TempFileSystem returns the temporary afero filesystem

type FilesystemParams

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

FilesystemParams contains parameter for instantiating a Filesystem storage backend

func NewFilesystemParams

func NewFilesystemParams(localStorageRoot string, localStorageWebRoot string) FilesystemParams

NewFilesystemParams returns FilesystemParams after checking path

type Memory

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

Memory is a storage backend that uses an in memory filesystem. It is intended only for use in development to avoid dependency on an external service.

func NewMemory

func NewMemory(params MemoryParams) *Memory

NewMemory creates a new Memory struct using the provided MemoryParams

func (*Memory) Delete

func (fs *Memory) Delete(key string) error

Delete deletes the file at the specified key

func (*Memory) Fetch

func (fs *Memory) Fetch(key string) (io.ReadCloser, error)

Fetch retrieves a copy of a file and stores it in a tempfile. The path to this file is returned.

It is the caller's responsibility to delete the tempfile.

func (*Memory) FileSystem

func (fs *Memory) FileSystem() *afero.Afero

FileSystem returns the underlying afero filesystem

func (*Memory) PresignedURL

func (fs *Memory) PresignedURL(key, contentType string) (string, error)

PresignedURL returns a URL that provides access to a file for 15 mintes.

func (*Memory) Store

func (fs *Memory) Store(key string, data io.ReadSeeker, _ string, _ *string) (*StoreResult, error)

Store stores the content from an io.ReadSeeker at the specified key.

func (*Memory) Tags

func (fs *Memory) Tags(_ string) (map[string]string, error)

Tags returns the tags for a specified key

func (*Memory) TempFileSystem

func (fs *Memory) TempFileSystem() *afero.Afero

TempFileSystem returns the temporary afero filesystem

type MemoryParams

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

MemoryParams contains parameter for instantiating a Memory storage backend

func NewMemoryParams

func NewMemoryParams(localStorageRoot string, localStorageWebRoot string) MemoryParams

NewMemoryParams returns default values for MemoryParams

type S3

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

S3 implements the file storage API using S3.

func NewS3

func NewS3(bucket, keyNamespace string, cfg aws.Config) *S3

NewS3 creates a new S3 using the provided AWS session.

func (*S3) Delete

func (s *S3) Delete(key string) error

Delete deletes an object at a specified key Use with caution, deletions are disabled on our S3 buckets as per our ATO.

func (*S3) Fetch

func (s *S3) Fetch(key string) (io.ReadCloser, error)

Fetch retrieves an object at a specified key and stores it in a tempfile. The path to this file is returned.

It is the caller's responsibility to cleanup this file.

func (*S3) FileSystem

func (s *S3) FileSystem() *afero.Afero

FileSystem returns the underlying afero filesystem

func (*S3) PresignedURL

func (s *S3) PresignedURL(key string, contentType string) (string, error)

PresignedURL returns a URL that provides access to a file for 15 minutes.

func (*S3) Store

func (s *S3) Store(key string, data io.ReadSeeker, checksum string, tags *string) (*StoreResult, error)

Store stores the content from an io.ReadSeeker at the specified key.

func (*S3) Tags

func (s *S3) Tags(key string) (map[string]string, error)

Tags returns the tags for a specified key

func (*S3) TempFileSystem

func (s *S3) TempFileSystem() *afero.Afero

TempFileSystem returns the temporary afero filesystem

type StoreResult

type StoreResult struct{}

StoreResult represents the result of a call to Store().

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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