27 Star 109 Fork 25

MJ PC Lab/go-http-file-server

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
path.go 990 Bytes
一键复制 编辑 原始数据 按行查看 历史
package util
import (
"path"
"path/filepath"
"strings"
)
func CleanUrlPath(urlPath string) string {
if len(urlPath) == 0 {
return "/"
}
if urlPath[0] != '/' {
urlPath = "/" + urlPath
}
urlPath = path.Clean(urlPath)
return urlPath
}
func HasUrlPrefixDir(urlPath, prefix string) bool {
if urlPath == prefix {
return true
}
if prefix[len(prefix)-1] != '/' {
prefix = prefix + "/"
}
return strings.HasPrefix(urlPath, prefix)
}
func HasFsPrefixDir(fsPath, prefix string) bool {
if fsPath == prefix {
return true
}
if prefix[len(prefix)-1] != filepath.Separator {
prefix = prefix + string(filepath.Separator)
}
return strings.HasPrefix(fsPath, prefix)
}
func NormalizeFsPath(input string) (string, error) {
abs, err := filepath.Abs(input)
if err != nil {
return abs, err
}
volume := filepath.VolumeName(abs)
if len(volume) > 0 {
// assume on windows platform, ignore ascii case in path name
abs = AsciiToLowerCase(abs)
}
return abs, err
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/mjpclab/go-http-file-server.git
git@gitee.com:mjpclab/go-http-file-server.git
mjpclab
go-http-file-server
go-http-file-server
v1.10.4

搜索帮助