file

package
v1.0.7 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2025 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

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 Save

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

对于常见图片格式进行压缩,并保存文件

Types

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"`      // 文件大小
	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" toml:"domain" yaml:"domain"` // 域名
	Static string `json:"static" toml:"static" yaml:"static"` // 静态文件目录
}

type Files

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

func NewFile

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

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"`
}

Jump to

Keyboard shortcuts

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