storage

package
v0.9.3 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2024 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound    = errors.New("file not found")
	ErrInvalidPath = errors.New("invalid file path")
)
View Source
var Module = fx.Module("storage",
	fx.Provide(New),
)

Functions

func FileNameSplitter

func FileNameSplitter(fileName string) string

func GetFilename

func GetFilename(uid string, fileName string, fileExtension string) string

Types

type FileInfo

type FileInfo struct {
	Name         string
	LastModified time.Time
	Size         int64
	ContentType  string
}

type Filesystem

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

func (*Filesystem) Delete

func (s *Filesystem) Delete(ctx context.Context, filePathIn string) error

func (*Filesystem) Get

func (s *Filesystem) Get(ctx context.Context, filePathIn string) (IObject, IObjectInfo, error)

func (*Filesystem) List

func (s *Filesystem) List(ctx context.Context, filePathIn string, offset int, pageSize int) ([]*FileInfo, error)

func (*Filesystem) Put

func (s *Filesystem) Put(ctx context.Context, filePathIn string, reader io.Reader, size int64, contentType string) (string, error)

func (*Filesystem) Stat

func (s *Filesystem) Stat(ctx context.Context, filePathIn string) (IObjectInfo, error)

func (*Filesystem) WithPrefix

func (s *Filesystem) WithPrefix(prefix string) (IStorage, error)

type IObject

type IObject interface {
	Read(p []byte) (n int, err error)
	ReadAt(p []byte, off int64) (n int, err error)
	Seek(offset int64, whence int) (int64, error)
	Close() error
}

type IObjectInfo

type IObjectInfo interface {
	GetName() string
	GetExtension() string
	GetContentType() string
	GetSize() int64
	GetLastModified() time.Time
	GetExpiration() time.Time
}

type IStorage

type IStorage interface {
	WithPrefix(prefix string) (IStorage, error)

	Get(ctx context.Context, filePath string) (IObject, IObjectInfo, error)
	Stat(ctx context.Context, filePath string) (IObjectInfo, error)
	Put(ctx context.Context, filePath string, reader io.Reader, size int64, contentType string) (string, error)
	Delete(ctx context.Context, filePath string) error

	List(ctx context.Context, filePath string, offset int, pageSize int) ([]*FileInfo, error)
}

func New

func New(p Params) (IStorage, error)

func NewFilesystem

func NewFilesystem(lc fx.Lifecycle, cfg *config.Config) (IStorage, error)

func NewNoop

func NewNoop(lc fx.Lifecycle, cfg *config.Config) (IStorage, error)

func NewS3

func NewS3(lc fx.Lifecycle, cfg *config.Config) (IStorage, error)

type Noop

type Noop struct{}

func (*Noop) Delete

func (s *Noop) Delete(ctx context.Context, filePath string) error

func (*Noop) Get

func (s *Noop) Get(ctx context.Context, filePath string) (IObject, IObjectInfo, error)

func (*Noop) List

func (s *Noop) List(ctx context.Context, filePath string, offset int, pageSize int) ([]*FileInfo, error)

func (*Noop) Put

func (s *Noop) Put(ctx context.Context, filePath string, reader io.Reader, size int64, contentType string) (string, error)

func (*Noop) Stat

func (s *Noop) Stat(ctx context.Context, filePath string) (IObjectInfo, error)

func (*Noop) WithPrefix

func (s *Noop) WithPrefix(prefix string) (IStorage, error)

type ObjectInfo

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

func (*ObjectInfo) GetContentType

func (o *ObjectInfo) GetContentType() string

func (*ObjectInfo) GetExpiration

func (o *ObjectInfo) GetExpiration() time.Time

func (*ObjectInfo) GetExtension

func (o *ObjectInfo) GetExtension() string

func (*ObjectInfo) GetFileInfo

func (o *ObjectInfo) GetFileInfo() *FileInfo

func (*ObjectInfo) GetLastModified

func (o *ObjectInfo) GetLastModified() time.Time

func (*ObjectInfo) GetName

func (o *ObjectInfo) GetName() string

func (*ObjectInfo) GetSize

func (o *ObjectInfo) GetSize() int64

type Params

type Params struct {
	fx.In

	LC     fx.Lifecycle
	Config *config.Config
}

type S3

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

func (*S3) Delete

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

func (*S3) Get

func (s *S3) Get(ctx context.Context, filePathIn string) (IObject, IObjectInfo, error)

func (*S3) List

func (s *S3) List(ctx context.Context, filePathIn string, offset int, pageSize int) ([]*FileInfo, error)

func (*S3) Put

func (s *S3) Put(ctx context.Context, filePathIn string, reader io.Reader, size int64, contentType string) (string, error)

Put the file path must end with a file extension (e.g., `jpg`, `png`)

func (*S3) PutWithTTL

func (s *S3) PutWithTTL(ctx context.Context, filePathIn string, reader io.Reader, size int64, contentType string, ttl time.Time) (string, error)

func (*S3) Stat

func (s *S3) Stat(ctx context.Context, filePathIn string) (IObjectInfo, error)

func (*S3) WithPrefix

func (s *S3) WithPrefix(prefix string) (IStorage, error)

Jump to

Keyboard shortcuts

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