代码拉取完成,页面将自动刷新
// Copyright 2019 chnykn@gmail.com All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package toolfunc
import (
"fmt"
"path"
"strings"
)
var illegalChars = [10]string{"/", "\n", "*", "\\", "<", ">", "|", "\"", ":", "?"}
func containsIllegalChar(value string) bool {
for _, c := range illegalChars {
n := strings.Count(value, c)
if n > 0 {
return true
}
}
return false
}
func getSuffix(fileName string) string {
var suffix string
suffix = path.Ext(fileName)
suffix = strings.TrimLeft(suffix, ".")
return suffix
}
//CheckFileName ***
func CheckFileName(fileName string) error {
if fileName == "" {
return fmt.Errorf("file name must not be empty")
}
if len(fileName) > 256 {
return fmt.Errorf("file name too long, no more than 256 characters")
}
suffix := getSuffix(fileName)
if suffix == "" {
return fmt.Errorf("file name has no suffix")
}
if containsIllegalChar(fileName) {
return fmt.Errorf("file name contains illegal character")
}
return nil
}
func CheckName(fileName string) error {
if fileName == "" {
return fmt.Errorf("file name must not be empty")
}
if len(fileName) > 150 {
return fmt.Errorf("file name too long, no more than 40 characters")
}
if containsIllegalChar(fileName) {
return fmt.Errorf("file name contains illegal character")
}
return nil
}
//CheckFileType ***
func CheckFileType(allSupportedType []string, fileName string) error {
suffix := strings.ToLower(getSuffix(fileName))
for _, typ := range allSupportedType {
if suffix == strings.ToLower(typ) {
return fmt.Errorf("file type not supported")
}
}
return nil
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。