helper

package
v2.0.6+incompatible Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2019 License: AGPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultUploadURLPath = `/public/upload/`
	DefaultUploadDir     = `./public/upload`
)

Variables

View Source
var (
	// UploadURLPath 上传文件网址访问路径
	UploadURLPath = DefaultUploadURLPath

	// UploadDir 定义上传目录(首尾必须带“/”)
	UploadDir = DefaultUploadDir

	// AllowedUploadFileExtensions 被允许上传的文件的扩展名
	AllowedUploadFileExtensions = []string{
		`.jpeg`, `.jpg`, `.gif`, `.png`,
	}

	// FileTypeIcon 文件类型icon
	FileTypeIcon = upload.FileTypeIcon

	// DetectFileType 根据文件扩展名判断文件类型
	DetectFileType = upload.DetectType

	// TypeRegister 注册文件扩展名
	TypeRegister = upload.TypeRegister
)
View Source
var (
	ErrUnsupportedExtension = errors.New("不支持的文件扩展名")
	ErrIncorrectPath        = errors.New("路径不合法")
)
View Source
var IsRightUploadFile = func(ctx echo.Context, src string) error {
	src = path.Clean(src)
	ext := strings.ToLower(path.Ext(src))
	if !com.InSlice(ext, AllowedUploadFileExtensions) {
		return errors.WithMessage(ErrIncorrectPath, ext)
	}
	if !strings.HasPrefix(src, UploadURLPath) {
		return ErrIncorrectPath
	}
	return nil
}

IsRightUploadFile 是否是正确的上传文件

View Source
var ParseAnyFileName = func(s string) []string {
	files := anyFileRegexp.FindAllString(s, -1)
	return files
}

ParseAnyFileName 从文本中解析出任意上传文件名称

View Source
var ParsePersistentFileName = func(s string) []string {
	files := persistentFileRegexp.FindAllString(s, -1)
	return files
}

ParsePersistentFileName 从文本中解析出正式文件名称

View Source
var ParseTemporaryFileName = func(s string) []string {
	files := temporaryFileRegexp.FindAllString(s, -1)
	return files
}

ParseTemporaryFileName 从文本中解析出临时文件名称

View Source
var ReplaceAnyFileName = func(s string, repl func(string) string) string {
	return anyFileRegexp.ReplaceAllStringFunc(s, repl)
}

ReplaceAnyFileName 从文本中替换任意上传文件名称

Functions

func ExtensionRegexpEnd

func ExtensionRegexpEnd() string

func ExtensionRegister

func ExtensionRegister(extensions ...string)

func ExtensionUnregister

func ExtensionUnregister(extensions ...string)

func FileTypeByName

func FileTypeByName(filename string) string

FileTypeByName 根据文件名判断文件类型

func Init

func Init()

func URLToFile

func URLToFile(fileURL string) string

URLToFile 文件网址转为存储路径

Types

This section is empty.

Jump to

Keyboard shortcuts

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