Documentation
¶
Index ¶
- func DownloadHandle(ctx context.Context, resp http.ResponseWriter, ds DownloadStorager, ...) (err error)
- func DownloadHandleWithRange(ctx context.Context, req *http.Request, resp http.ResponseWriter, ...) (err error)
- func FromDownloadFilenameContext(ctx context.Context) (downloadFilename string, ok bool)
- func GetMultipartFileSize(file multipart.File) (size int64, err error)
- func NewDownloadBeforeContext(ctx context.Context, f DownloadBefore) context.Context
- func NewDownloadFilenameContext(ctx context.Context, downloadFilename string) context.Context
- func NewIncomingContext(ctx context.Context, md Metadata) context.Context
- func NewRangeRequestContext(ctx context.Context, start, end int64) context.Context
- func NewRenameContext(ctx context.Context, f Rename) context.Context
- type DefaultDownloadStorage
- type DefaultStorage
- func (ds *DefaultStorage) Download(ctx context.Context, dist io.Writer, filename string) (info DownloadFileInfoer, err error)
- func (ds *DefaultStorage) Exist(_ context.Context, filename string) (exist bool, err error)
- func (ds *DefaultStorage) Remove(_ context.Context, filename string) (err error)
- func (ds *DefaultStorage) Upload(ctx context.Context, read io.Reader, filename string) (fullName string, err error)
- type DefaultUploadStorage
- type DownloadBefore
- type DownloadFileInfoer
- type DownloadStorager
- type Downloader
- type Exister
- type Metadata
- type RangeRequest
- type Remover
- type Rename
- type Storager
- type UploadFileInfoer
- type UploadStorager
- type Uploader
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 DownloadHandleWithRange ¶
func DownloadHandleWithRange(ctx context.Context, req *http.Request, resp http.ResponseWriter, ds DownloadStorager, filename string) (err error)
DownloadHandleWithRange 支持范围请求的下载处理
func FromDownloadFilenameContext ¶
FromDownloadFilenameContext ...
func GetMultipartFileSize ¶
GetMultipartFileSize 获取上传文件大小 相关问题:https://github.com/golang/go/issues/19501
func NewDownloadBeforeContext ¶
func NewDownloadBeforeContext(ctx context.Context, f DownloadBefore) context.Context
NewDownloadBeforeContext ...
func NewDownloadFilenameContext ¶
NewDownloadFilenameContext ...
func NewIncomingContext ¶
NewIncomingContext creates a new context with incoming md attached.
func NewRangeRequestContext ¶
NewRangeRequestContext 创建包含Range请求的context start: 开始字节位置(>=0)。如果<0,表示读取最后-start个字节(Suffix Range) end: 结束字节位置(>=start,或<0表示到文件末尾)。对于Suffix Range,此参数被忽略 例如:start=0, end=99 表示读取前100个字节(0到99)
start=100, end=-1 表示从第101个字节读取到文件末尾 start=0, end=-1 表示读取整个文件 start=-500, end=0 表示读取最后500个字节
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 (*DefaultStorage) Download ¶
func (ds *DefaultStorage) Download(ctx context.Context, dist io.Writer, filename string) (info DownloadFileInfoer, err error)
Download 下载
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 Metadata ¶
Metadata 元数据
func FromIncomingContext ¶
FromIncomingContext returns the incoming metadata in ctx if it exists.
type RangeRequest ¶
type RangeRequest struct {
Start int64 // 开始字节位置(包含),从0开始。如果<0,表示读取最后-Start个字节(Suffix Range)
End int64 // 结束字节位置(包含),<0表示到文件末尾
}
RangeRequest 表示Range请求
func FromRangeRequestContext ¶
func FromRangeRequestContext(ctx context.Context) (rangeReq *RangeRequest, ok bool)
FromRangeRequestContext 从context中获取Range请求
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 ¶
UploadStorager 上传接口