storage

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 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 added in v0.8.20

func FileNameSplitter(fileName string) string

func GetFilename added in v0.8.20

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

Types

type FileInfo added in v0.8.20

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

type Filesystem added in v0.8.20

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

func (*Filesystem) Delete added in v0.8.20

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

func (*Filesystem) Get added in v0.8.20

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

func (*Filesystem) List added in v0.8.20

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

func (*Filesystem) Put added in v0.8.20

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

func (*Filesystem) Stat added in v0.8.20

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

func (*Filesystem) WithPrefix added in v0.8.20

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

type IObject added in v0.8.20

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 added in v0.8.20

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

type IStorage added in v0.8.20

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 added in v0.8.20

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

func NewNoop added in v0.8.21

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

func NewS3 added in v0.8.20

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

type Noop added in v0.8.21

type Noop struct{}

func (*Noop) Delete added in v0.8.21

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

func (*Noop) Get added in v0.8.21

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

func (*Noop) List added in v0.8.21

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

func (*Noop) Put added in v0.8.21

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

func (*Noop) Stat added in v0.8.21

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

func (*Noop) WithPrefix added in v0.8.21

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

type ObjectInfo added in v0.8.20

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

func (*ObjectInfo) GetContentType added in v0.8.20

func (o *ObjectInfo) GetContentType() string

func (*ObjectInfo) GetExpiration added in v0.8.20

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

func (*ObjectInfo) GetExtension added in v0.8.20

func (o *ObjectInfo) GetExtension() string

func (*ObjectInfo) GetFileInfo added in v0.8.21

func (o *ObjectInfo) GetFileInfo() *FileInfo

func (*ObjectInfo) GetLastModified added in v0.8.21

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

func (*ObjectInfo) GetName added in v0.8.21

func (o *ObjectInfo) GetName() string

func (*ObjectInfo) GetSize added in v0.8.20

func (o *ObjectInfo) GetSize() int64

type Params added in v0.8.21

type Params struct {
	fx.In

	LC     fx.Lifecycle
	Config *config.Config
}

type S3 added in v0.8.20

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

func (*S3) Delete added in v0.8.20

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

func (*S3) Get added in v0.8.20

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

func (*S3) List added in v0.8.20

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

func (*S3) Put added in v0.8.20

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 added in v0.8.20

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

func (*S3) Stat added in v0.8.20

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

func (*S3) WithPrefix added in v0.8.20

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