helper

package
v2.0.4+incompatible Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2019 License: AGPL-3.0 Imports: 5 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`,
	}
)
View Source
var IsRightUploadFile = func(ctx echo.Context, src string) error {
	src = path.Clean(src)
	ext := strings.ToLower(path.Ext(src))
	var ok bool
	var invalidExt string
	for _, ex := range AllowedUploadFileExtensions {
		if ext == ex {
			ok = true
			invalidExt = ext
			break
		}
	}
	if !ok {
		return ctx.E(`不支持的文件扩展名: %s`, invalidExt)
	}
	if !strings.Contains(src, UploadURLPath) {
		return ctx.E(`路径不合法`)
	}
	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 Init

func Init()

Types

This section is empty.

Jump to

Keyboard shortcuts

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