upload

package
v0.0.0-...-c6f1323 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2022 License: GPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckContainExt

func CheckContainExt(t FileType, name string) bool

func CheckMaxsize

func CheckMaxsize(t FileType, f multipart.File) bool

CheckMaxsize 检查文件大小是否超出最大大小限制。

func CheckPermission

func CheckPermission(dst string) bool

CheckPermission 检查文件权限是否足够,与 CheckSavePath 方法原理一致,是利用 oserror.ErrPermission 进行判断。

func CheckSavePath

func CheckSavePath(dst string) bool

CheckSavePath 检查保存目录是否存在,通过调用 os.Stat 方法获取文件的描述信息 FileInfo,并调用 os.IsNotExist 方法进行判断,其原理是利用 os.Stat 方法所返回的 error 值与系统中所定义的 oserror.ErrNotExist 进行判断,以此达到校验效果

func CreateSavePath

func CreateSavePath(dst string, perm os.FileMode) error

CreateSavePath 创建在上传文件时所使用的保存目录,在方法内部调用的 os.MkdirAll 方法,该方法将会以传入的 os.FileMode 权限位去递归创建所需的所有目录结构,若涉及的目录均已存在,则不会进行任何操作,直接返回 nil。

func GetFileExt

func GetFileExt(name string) string

GetFileExt 获取文件后缀,主要是通过调用 path.Ext 方法进行循环查找”.“符号,最后通过切片索引返回对应的文化后缀名称。

func GetFileName

func GetFileName(name string) string

GetFileName 获取文件名称,先是通过获取文件后缀并筛出原始文件名进行 MD5 加密,最后返回经过加密处理后的文件名。

func GetSavePath

func GetSavePath(t FileType) string

GetSavePath 获取文件保存地址,这里直接返回配置中的文件保存目录即可,也便于后续的调整。

func GetUrlSavePath

func GetUrlSavePath(t FileType) string

GetUrlSavePath 获取文件保存URl,这里直接返回URL

func IsMarkdownExist

func IsMarkdownExist(name string) bool

func SavaFile

func SavaFile(file *multipart.FileHeader, dst string) error

SavaFile 保存所上传的文件,该方法主要是通过调用 os.Create 方法创建目标地址的文件,再通过 file.Open 方法打开源地址的文件,结合 io.Copy 方法实现两者之间的文件内容拷贝

Types

type FileType

type FileType int
const (
	TypeImage FileType = iota + 1
	TypeMarkdown
	TypeExcel
	TypeTxt
)

Jump to

Keyboard shortcuts

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