You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
48 lines
904 B
48 lines
904 B
package util
|
|
|
|
import (
|
|
"path"
|
|
"strings"
|
|
)
|
|
|
|
// DotPathToStandardPath 将","分割的路径转换为标准路径
|
|
func DotPathToStandardPath(path string) string {
|
|
return "/" + strings.Replace(path, ",", "/", -1)
|
|
}
|
|
|
|
// FillSlash 给路径补全`/`
|
|
func FillSlash(path string) string {
|
|
if path == "/" {
|
|
return path
|
|
}
|
|
return path + "/"
|
|
}
|
|
|
|
// RemoveSlash 移除路径最后的`/`
|
|
func RemoveSlash(path string) string {
|
|
if len(path) > 1 {
|
|
return strings.TrimSuffix(path, "/")
|
|
}
|
|
return path
|
|
}
|
|
|
|
// SplitPath 分割路径为列表
|
|
func SplitPath(path string) []string {
|
|
if len(path) == 0 || path[0] != '/' {
|
|
return []string{}
|
|
}
|
|
|
|
if path == "/" {
|
|
return []string{"/"}
|
|
}
|
|
|
|
pathSplit := strings.Split(path, "/")
|
|
pathSplit[0] = "/"
|
|
return pathSplit
|
|
}
|
|
|
|
// FormSlash 将path中的反斜杠'\'替换为'/'
|
|
func FormSlash(old string) string {
|
|
return path.Clean(strings.ReplaceAll(old, "\\", "/"))
|
|
}
|