init commit

This commit is contained in:
notch
2020-12-10 08:53:42 +08:00
parent 031a0531bd
commit b47b0cd6c2
61 changed files with 31801 additions and 12 deletions

37
utils/path.go Executable file
View File

@@ -0,0 +1,37 @@
// Copyright (c) 2019,CAOHONGJU All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package utils
import (
"path"
"strings"
)
// CanonicalPath 获取合法的path
func CanonicalPath(p string) string {
p = strings.ToLower(strings.TrimSpace(p))
if p == "" {
return "/"
}
if p[0] != '/' {
p = "/" + p
}
np := path.Clean(p)
// path.Clean removes trailing slash except for root;
// put the trailing slash back if necessary.
if p[len(p)-1] == '/' && np != "/" {
// Fast path for common case of p being the string we want:
if len(p) == len(np)+1 && strings.HasPrefix(p, np) {
np = p
} else {
np += "/"
}
}
return np
}