sizedupload

package module
v0.0.0-...-72fbc82 Latest Latest
Warning

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

Go to latest
Published: Jan 31, 2023 License: MIT Imports: 19 Imported by: 0

README

sizedupload

支持设置上传文件大小的、快速组件,当文件大小超过限制时及时中断文件上传

Documentation

Index

Constants

This section is empty.

Variables

View Source
var UploadConfig = &upConfig{
	MemoryLimit: int64(512 * 1024),
	Logger:      &defaultLogger{},
}

Functions

func SizeUploadHandler

func SizeUploadHandler(req *http.Request, urlPath string, w http.ResponseWriter, fileHandler ProcessFileHandler)

Types

type BizConf

type BizConf struct {
	BizLine   string        `yaml:"bizLine,omitempty"`
	MaxLength int64         `yaml:"maxLength,omitempty"`
	Subs      []BizLineConf `yaml:"subs,omitempty"`
}

type BizLineConf

type BizLineConf struct {
	BizLine   string `yaml:"bizLine,omitempty"`
	MaxLength int64  `yaml:"maxLength,omitempty"`
}

type GetUploadUser

type GetUploadUser func(req *http.Request, ctx context.Context) int64

type Logger

type Logger interface {
	LogInfo(format string, args ...any)
	LogError(format string, args ...any)
}

type ParsedFile

type ParsedFile struct {
	FormData map[string]string

	FileData *struct {
		OriginName string
		Size       int64
		Content    []byte
		// contains filtered or unexported fields
	}
}

type ProcessFileHandler

type ProcessFileHandler func(file *ParsedFile, userId int64, context context.Context) (*ProcessFileResult, error)

type ProcessFileResult

type ProcessFileResult struct {
	Id             int64  `json:"id"`
	TargetFileName string `json:"targetFileName"`
}

type Result

type Result struct {
	Success bool   `json:"success"`
	Code    int    `json:"code,omitempty"`
	Message string `json:"message"`
	Data    any    `json:"data,omitempty"`
}

type ResultOutput

type ResultOutput interface {
	OutputResult(w http.ResponseWriter, ctx context.Context, result *ProcessFileResult)
	OutputExceed(w http.ResponseWriter, ctx context.Context)
	OutputNoAuth(w http.ResponseWriter, ctx context.Context)
	OutputErr(w http.ResponseWriter, ctx context.Context, err error)
}

func NewJsonResultOutput

func NewJsonResultOutput() ResultOutput

type SizeProvider

type SizeProvider interface {
	GetSize(url string, ctx context.Context) int64
}

func NewConfSizeProvider

func NewConfSizeProvider() (SizeProvider, error)

func NewConfSizeProviderByConfFile

func NewConfSizeProviderByConfFile(confFile string) (SizeProvider, error)

type YamlConfig

type YamlConfig struct {
	Global  int64     `yaml:"global,omitempty"`
	Configs []BizConf `yaml:"configs,omitempty"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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