filestore

package
v0.8.3 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2023 License: Apache-2.0, MIT Imports: 18 Imported by: 0

Documentation

Overview

Package filestore stores files in various types of storage systems.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type File

type File struct {
	// Modified it the last modification time.
	Modified time.Time
	// Path is the path to the file relative to the root of the file store.
	// Path separators are always slash ('/') characters.
	Path string
	// Size if the number of bytes of data in the file.
	Size int64
	// URL is a URL where the file can be retrieved from, if available.
	URL string
}

File contains information about a stored file.

type Interface

type Interface interface {
	// Delete removes the specified file from storage.
	Delete(ctx context.Context, path string) error
	// Get retrieves the specified file from storage. Returns fs.ErrNotExist if
	// file is not count.
	Get(ctx context.Context, path string) (*File, io.ReadCloser, error)
	// Head gets information about the specified file in storage. Returns
	// fs.ErrNotExist if file is not count.
	Head(ctx context.Context, path string) (*File, error)
	// List returns a series of *File on the first channel returned. If an
	// error occurs, the first channel is closed and the error is returned on
	// the second channel.
	List(ctx context.Context, path string, recursive bool) (<-chan *File, <-chan error)
	// Put writes a file to storage. A nil reader creates an empty file.
	Put(ctx context.Context, path string, reader io.Reader) (*File, error)
	// Type returns the file store type.
	Type() string
}

Interface is the interface supported by all file store implementations. All Path arguments are relative to the root of the file store and always use slash ('/') characters.

type Local

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

Local is a file store that stores files in the local file system.

func NewLocal

func NewLocal(basePath string) (*Local, error)

func (*Local) Delete

func (l *Local) Delete(ctx context.Context, relPath string) error

func (*Local) Get

func (l *Local) Get(ctx context.Context, relPath string) (*File, io.ReadCloser, error)

func (*Local) Head

func (l *Local) Head(ctx context.Context, relPath string) (*File, error)

func (*Local) List

func (l *Local) List(ctx context.Context, relPath string, recursive bool) (<-chan *File, <-chan error)

func (*Local) Put

func (l *Local) Put(ctx context.Context, relPath string, r io.Reader) (*File, error)

func (*Local) Type

func (l *Local) Type() string

type S3

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

S3 is a file store that stores files in AWS S3.

The region is set by environment variable and authentication is done by assuming a role, which is handled by infrastructure.

func NewS3

func NewS3(bucketName string, options ...S3Option) (*S3, error)

func (*S3) Delete

func (s *S3) Delete(ctx context.Context, relPath string) error

func (*S3) Get

func (s *S3) Get(ctx context.Context, relPath string) (*File, io.ReadCloser, error)

func (*S3) Head

func (s *S3) Head(ctx context.Context, relPath string) (*File, error)

func (*S3) List

func (s *S3) List(ctx context.Context, relPath string, recursive bool) (<-chan *File, <-chan error)

func (*S3) Put

func (s *S3) Put(ctx context.Context, relPath string, reader io.Reader) (*File, error)

func (*S3) Type

func (s *S3) Type() string

type S3Option

type S3Option func(*s3Config) error

func WithEndpoint

func WithEndpoint(ep string) S3Option

func WithKeys

func WithKeys(accessKey, secretKey string) S3Option

func WithRegion

func WithRegion(region string) S3Option

Jump to

Keyboard shortcuts

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