storage

package
v0.0.0-...-e8513ac Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DownloadHandler

func DownloadHandler(ctx context.Context,
	w http.ResponseWriter, storage DownloadStorager, filename string) (err error)

func FromDownloadFilenameContext

func FromDownloadFilenameContext(ctx context.Context) (filename string, ok bool)

func GetMultipartFileSize

func GetMultipartFileSize(file multipart.File) (size int64, err error)

GetMultipartFileSize 获取上传文件大小 相关问题:https://github.com/golang/go/issues/19501

func NewDownloadBeforeContext

func NewDownloadBeforeContext(ctx context.Context, f DownloadBeforeFunc) context.Context

func NewDownloadFilenameContext

func NewDownloadFilenameContext(ctx context.Context, filename string) context.Context

func NewIncomingContext

func NewIncomingContext(ctx context.Context, md Metadata) context.Context

func NewRenameContext

func NewRenameContext(ctx context.Context, f RenameFunc) context.Context

Types

type DefaultDownloadStorage

type DefaultDownloadStorage struct {
	*DefaultStorage
	// contains filtered or unexported fields
}

func NewDefaultDownloadStorage

func NewDefaultDownloadStorage(dispositionType string) *DefaultDownloadStorage

func (*DefaultDownloadStorage) DispositionType

func (ds *DefaultDownloadStorage) DispositionType() string

type DefaultStorage

type DefaultStorage struct {
	BasePath string
}

func NewDefaultStorage

func NewDefaultStorage() *DefaultStorage

func (*DefaultStorage) Download

func (ds *DefaultStorage) Download(ctx context.Context,
	writer io.Writer, filename string) (info DownloadFileInfoer, err error)

func (*DefaultStorage) Exist

func (ds *DefaultStorage) Exist(ctx context.Context, filename string) (exist bool, err error)

func (*DefaultStorage) Remove

func (ds *DefaultStorage) Remove(ctx context.Context, filename string) (err error)

func (*DefaultStorage) Upload

func (ds *DefaultStorage) Upload(ctx context.Context,
	reader io.Reader, filename string) (fullName string, err error)

type DefaultUploadStorage

type DefaultUploadStorage struct {
	*DefaultStorage
}

func NewDefaultUploadStorage

func NewDefaultUploadStorage() *DefaultUploadStorage

func (*DefaultUploadStorage) MaxMemory

func (ds *DefaultUploadStorage) MaxMemory() int64

type DownloadBeforeFunc

type DownloadBeforeFunc func(info DownloadFileInfoer)

func FromDownloadBeforeContext

func FromDownloadBeforeContext(ctx context.Context) (f DownloadBeforeFunc, ok bool)

type DownloadFileInfoer

type DownloadFileInfoer interface {
	Size() int64
	Filename() string
	Metadata() Metadata
}

type DownloadStorager

type DownloadStorager interface {
	Downloader
	DispositionType() string
}

type Downloader

type Downloader interface {
	Download(ctx context.Context, writer io.Writer, filename string) (info DownloadFileInfoer, err error)
}

type Exister

type Exister interface {
	Exist(ctx context.Context, filename string) (exist bool, err error)
}

type Metadata

type Metadata map[string]string

func FromIncomingContext

func FromIncomingContext(ctx context.Context) (md Metadata, ok bool)

func (Metadata) Get

func (md Metadata) Get(k string) string

func (Metadata) Set

func (md Metadata) Set(k, v string)

type Remover

type Remover interface {
	Remove(ctx context.Context, filename string) (err error)
}

type RenameFunc

type RenameFunc func(filename string) string

func FromRenameContext

func FromRenameContext(ctx context.Context) (f RenameFunc, ok bool)

type Storager

type Storager interface {
	Uploader
	Downloader
	Remover
	Exister
}

type UploadFileInfoer

type UploadFileInfoer interface {
	FullName() string
	Filename() string
	Size() int64
	Header() textproto.MIMEHeader
}

func UploadHandler

func UploadHandler(ctx context.Context,
	r *http.Request, storage UploadStorager, name string) (infos []UploadFileInfoer, err error)

type UploadStorager

type UploadStorager interface {
	Uploader
	MaxMemory() int64
}

type Uploader

type Uploader interface {
	Upload(ctx context.Context, reader io.Reader, filename string) (fullName string, err error)
}

Jump to

Keyboard shortcuts

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