file

package
v2.0.1 Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const UPLOAD_DIR = "upload"

Variables

This section is empty.

Functions

func Domain

func Domain(r *http.Request, domain string) (string, error)

func FileMimeType

func FileMimeType(path string) (string, error)

func List

func List[T any](page int32, pageSize int32, list []T) (total, totalPage int64, res []T)

List 数据做分页

func Save

func Save(file *multipart.FileHeader, path string, compress bool) (size int64, err error)

Types

type Config

type Config struct {
	MaxImageSize int64    // 最大图片大小
	MaxVideoSize int64    // 最大视频大小
	MaxOtherSize int64    // 最大其他文件大小
	Extensions   []string // 允许的文件扩展名
	BasePath     string   // 基础路径
	PathHasBase  bool     // 访问路径是否包含基础路径
	Domain       string   // 域名
}

type File

type File struct {
	Name      string `json:"name"`      // 文件名,不包含扩展名
	Extension string `json:"extension"` // 扩展名
	FullName  string `json:"full_name"` // 文件名,包含扩展名
	Path      string `json:"path"`      // 文件保存路径
	Url       string `json:"url"`       // 文件访问路径
	Size      int64  `json:"size"`      // 文件大小
	FileType  string `json:"file_type"` // 文件类型:image、video、other、dir
	Type      string `json:"type"`      // 文件类型:image、video、other、dir 兼容旧版本
	IsDir     bool   `json:"is_dir"`    // 是否是文件夹
	ModTime   string `json:"mod_time"`  // 修改时间
	Mime      string `json:"mime"`      // 文件mime
}

type FileConfig

type FileConfig struct {
	Domain           string `json:"domain"`             // 域名
	Static           string `json:"static"`             // 静态文件目录
	NotIncludeStatic bool   `json:"not_include_static"` // 访问路径是否不包含静态目录
}

type Files

type Files struct {
	Request *http.Request
	Config  *FileConfig
}

func NewFile

func NewFile(request *http.Request, cfg *FileConfig) *Files

func (*Files) Base64ToFile

func (f *Files) Base64ToFile(b64 string, dir string, l Limit) (*File, error)

func (*Files) Delete

func (f *Files) Delete(path string, name string) error

func (*Files) GetPath

func (f *Files) GetPath(dir string, types string) (string, error)

func (*Files) List

func (f *Files) List(param ListParam) (*ListRes, error)

func (*Files) Upload

func (f *Files) Upload(file *multipart.FileHeader, dir string, l Limit) (*File, error)

type Limit

type Limit struct {
	ImageMaxSize int64
	VideoMaxSize int64
	OtherMaxSize int64
	Extension    string
	Compress     bool
}

type ListParam

type ListParam struct {
	Path     string
	Name     string
	Page     int
	PageSize int
}

type ListRes

type ListRes struct {
	Data  []File `json:"data"`
	Total int64  `json:"total"`
}

type Upload

type Upload struct {
	Dir   string
	File  *File
	Error error
	// contains filtered or unexported fields
}

func NewUpload

func NewUpload(file *multipart.FileHeader, config *Config) *Upload

func (*Upload) GetFile

func (u *Upload) GetFile() (*File, error)

func (*Upload) Limit

func (u *Upload) Limit() *Upload

func (*Upload) Save

func (u *Upload) Save(compress bool) *Upload

func (*Upload) SetDir

func (u *Upload) SetDir(dir string) *Upload

func (*Upload) VerifType

func (u *Upload) VerifType(t string) *Upload

Jump to

Keyboard shortcuts

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