filestore

package
v0.21.6 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2020 License: Apache-2.0 Imports: 5 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrFileStore is the general error for this package.
	ErrFileStore = errors.New("file store")
	// ErrStore is the error with the store by itself.
	ErrStore = errors.Wrap(ErrFileStore, "store")
	// ErrVersionsNotAllowed is an error if the store doesn't support file versions.
	ErrVersionsNotAllowed = errors.Wrap(ErrStore, "versions not allowed")
	// ErrFileName is an error for invalid file names.
	ErrFileName = errors.Wrap(ErrFileStore, "file name")
	// ErrExists is an error if the file already exists.
	ErrExists = errors.Wrap(ErrFileStore, "exists")
	// ErrFileIsDir is an error if provided file name is a directory.
	ErrFileIsDir = errors.Wrap(ErrFileStore, "file is dir")
	// ErrNotExists is an error when the file doesn't exists.
	ErrNotExists = errors.Wrap(ErrFileStore, "not exists")
	// ErrNotOpened is an error if the file is not opened yet and wanted to be read.
	ErrNotOpened = errors.Wrap(ErrFileStore, "not opened")
	// ErrAlreadyOpened is an error thrown when the file is already opened.
	ErrAlreadyOpened = errors.Wrap(ErrFileStore, "already opened")
	// ErrClosed is an error if the file is already closed.
	ErrClosed = errors.Wrap(ErrFileStore, "closed")
	// ErrInternal is an internal error for this package.
	ErrInternal = errors.Wrap(errors.ErrInternal, "file store")
	// ErrPermission is an error with the file permissions.
	ErrPermission = errors.Wrap(ErrFileStore, "permission")
)
View Source
var MimeTypes = map[string]string{

	"css":  "text/css",
	"html": "text/html",
	"txt":  "text/plain",

	"gif":  "image/gif",
	"jpeg": "image/jpeg",
	"png":  "image/png",
	"tiff": "image/tiff",
	"ico":  "image/vnd.microsoft.icon",

	"js":   "application/javascript",
	"json": "application/json",
	"xml":  "application/xml",

	"mp3": "audio/mpeg",
	"wma": "audio/x-ms-wma",
	"ra":  "audio/vnd.rn-realaudio",
	"rm":  "audio/vnd.rn-realaudio",
	"ram": "audio/vnd.rn-realaudio",
	"wav": "audio/x-wav",

	"mpeg": "video/mpeg",
	"mp4":  "video/mp4",
	"wmv":  "video/x-ms-wmv",
	"qt":   "video/quicktime",
	"mov":  "video/quicktime",
}

MimeTypes are the file extension well-known mime types.

Functions

func GetMimeType

func GetMimeType(file File) string

GetMimeType gets the default mime type for given file extension.

Types

type File

type File interface {
	// Name returns file name with extension.
	Name() string
	// Bucket returns file's bucket.
	Bucket() string
	// Directory returns file directory.
	Directory() string
	// Version returns file version.
	Version() string

	// Parameters obtainable after open.
	// ModifiedAt is the last modification time.
	ModifiedAt() time.Time
	// Size returns byte size of given file.
	Size() int64

	// I/O
	//
	// Read functions.
	//
	// Open opens the file in an read-only way.
	Open(ctx context.Context) error
	// Close after successful read the file needs to be closed.
	Close(ctx context.Context) error
	// Read the file content when it is opened. Implements io.Reader
	Read(data []byte) (int, error)

	// Write the file content Implements io.Writer. The write is independent of the Open -> Read -> Close cycle.
	// In order to store the changes the file needs to be put into the store.
	Write(data []byte) (int, error)
}

File is a basic interface for the file abstraction.

type FileOption

type FileOption func(o *FileOptions)

FileOption is function that changes file options.

func FileWithBucket

func FileWithBucket(bucket string) FileOption

FileWithBucket create file with provided bucket.

func FileWithDirectory

func FileWithDirectory(directory string) FileOption

FileWithDirectory create the file with given 'directory'.

type FileOptions

type FileOptions struct {
	Directory string
	Bucket    string
}

FileOptions are the options file creating new file.

type GetOption

type GetOption func(o *GetOptions)

GetOption is an option function that set get options.

func GetWithBucket

func GetWithBucket(bucket string) GetOption

GetWithBucket get file with provided bucket.

func GetWithDirectory

func GetWithDirectory(directory string) GetOption

GetWithDirectory sets the get file options with 'directory'.

func GetWithVersion

func GetWithVersion(version string) GetOption

GetWithVersion gets the file with given version. Used only for get method.

type GetOptions

type GetOptions struct {
	Directory string
	Bucket    string
	Version   string
}

GetOptions are the options while getting the file.

type ListOption

type ListOption func(o *ListOptions)

ListOption is a function that sets up list options.

func ListWithBucket

func ListWithBucket(bucket string) ListOption

ListWithBucket sets the list bucket filter.

func ListWithExtension

func ListWithExtension(ext string) ListOption

ListWithExtension sets the list extension filter.

func ListWithLimit

func ListWithLimit(limit int) ListOption

ListWithLimit sets the list limit filter.

func ListWithOffset

func ListWithOffset(offset int) ListOption

ListWithOffset sets the list offset filter.

type ListOptions

type ListOptions struct {
	// Limit, Offset sets the limit and offset while listing the files.
	Limit, Offset int
	// Extension is a filter type of the file extension.
	Extension string
	// Bucket could be used for S3 implementations.
	Bucket string
}

ListOptions are the settings while listing the files.

type Metadater

type Metadater interface {
	Metadata() map[string]interface{}
	GetMeta(key string) (interface{}, bool)
	SetMeta(key string, value interface{})
}

Metadater is an interface used

type Model

type Model interface {
	mapping.Model
	// BucketField returns golang name for the bucket field.
	BucketField() string
	// DirectoryField returns golang name for the directory field.
	DirectoryField() string
	// NameField returns golang name for the file name field.
	NameField() string
	// VersionField returns golang name for the version field.
	VersionField() string
	// ExtensionField returns golang name for the file extension field.
	ExtensionField() string
}

Model is the interface that defines file model.

type PutOption

type PutOption func(o *PutOptions)

PutOption is the function that changes the put options.

func PutWithOverwrite

func PutWithOverwrite() PutOption

PutWithOverwrite is the put option that forces the put to overwrite given file.

type PutOptions

type PutOptions struct {
	// Overwrite defines if the file with given version should be overwritten by the input.
	Overwrite bool
}

PutOptions are the options used on putting the file.

type Store

type Store interface {
	// Type returns the name of the file store.
	Type() string
	// NewFile creates new file with given name and with provided options.
	NewFile(ctx context.Context, name string, options ...FileOption) (File, error)
	// PutFile stores the file created previously.
	PutFile(ctx context.Context, file File, options ...PutOption) error
	// GetFile gets the file header with provided name (only file name with extension) and possible options.
	GetFile(ctx context.Context, name string, options ...GetOption) (File, error)
	// ListFiles lists the file headers for provided directory with optional filters.
	ListFiles(ctx context.Context, dir string, options ...ListOption) ([]File, error)
	// DeleteFile deletes provided file.
	DeleteFile(ctx context.Context, file File) error
}

Store is an interface that allows to execute operation on files.

Jump to

Keyboard shortcuts

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