storage

package
v0.0.0-...-8725c39 Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2023 License: MIT Imports: 9 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DownloadHandle

func DownloadHandle(ctx context.Context, resp http.ResponseWriter, ds DownloadStorager, filename string) (err error)

DownloadHandle 下载处理

func FromDownloadFilenameContext

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

FromDownloadFilenameContext ...

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 DownloadBefore) context.Context

NewDownloadBeforeContext ...

func NewDownloadFilenameContext

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

NewDownloadFilenameContext ...

func NewIncomingContext

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

NewIncomingContext creates a new context with incoming md attached.

func NewRenameContext

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

NewRenameContext ...

Types

type DefaultDownloadStorage

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

DefaultDownloadStorage 默认下载

func NewDefaultDownloadStorage

func NewDefaultDownloadStorage(dispositionType string) *DefaultDownloadStorage

NewDefaultDownloadStorage 创建默认存储

func (*DefaultDownloadStorage) DispositionType

func (d *DefaultDownloadStorage) DispositionType() string

DispositionType Disposition Type

type DefaultStorage

type DefaultStorage struct {
	BasePath string
}

DefaultStorage 默认存储

func NewDefaultStorage

func NewDefaultStorage() *DefaultStorage

NewDefaultStorage 创建默认存储

func (*DefaultStorage) Download

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

Download 下载

func (*DefaultStorage) Exist

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

Exist 是否存在

func (*DefaultStorage) Remove

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

Remove 删除

func (*DefaultStorage) Upload

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

Upload 上传

type DefaultUploadStorage

type DefaultUploadStorage struct {
	*DefaultStorage
}

DefaultUploadStorage 默认上传

func NewDefaultUploadStorage

func NewDefaultUploadStorage() *DefaultUploadStorage

NewDefaultUploadStorage 创建默认存储

func (*DefaultUploadStorage) MaxMemory

func (*DefaultUploadStorage) MaxMemory() int64

MaxMemory 最大上传大小

type DownloadBefore

type DownloadBefore func(info DownloadFileInfoer)

DownloadBefore 下载之前

func FromDownloadBeforeContext

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

FromDownloadBeforeContext ...

type DownloadFileInfoer

type DownloadFileInfoer interface {
	// Size 文件大小
	Size() int64
	// Filename 文件名
	Filename() string
	// Metadata 获取元数据
	Metadata() Metadata
}

DownloadFileInfoer 下载file信息接口

type DownloadStorager

type DownloadStorager interface {
	Downloader
	DispositionType() string
}

DownloadStorager 下载接口

type Downloader

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

Downloader 下载

type Exister

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

type Metadata

type Metadata map[string]string

Metadata 元数据

func FromIncomingContext

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

FromIncomingContext returns the incoming metadata in ctx if it exists.

func (Metadata) Get

func (md Metadata) Get(k string) string

Get obtains the value for a given key.

func (Metadata) Set

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

Set sets the value of a given key with a slice of value.

type Remover

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

Remover 删除

type Rename

type Rename func(filename string) string

Rename 重命名

func FromRenameContext

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

FromRenameContext ...

type Storager

type Storager interface {
	Uploader
	Downloader
	Remover
	Exister
}

Storager 存储

type UploadFileInfoer

type UploadFileInfoer interface {
	// FullName 完整的文件名
	// 包含路径
	FullName() string
	// Filename 文件名
	Filename() string
	// Size 文件大小
	Size() int64
	// Header 获取MIMEHeader
	Header() textproto.MIMEHeader
}

UploadFileInfoer 上传file信息接口

func UploadHandle

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

UploadHandle 上传处理

type UploadStorager

type UploadStorager interface {
	Uploader
	MaxMemory() int64
}

UploadStorager 上传接口

type Uploader

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

Uploader 上传

Jump to

Keyboard shortcuts

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