49 lines
510 B
Go
49 lines
510 B
Go
package server
|
|
|
|
import (
|
|
"strings"
|
|
)
|
|
|
|
func cleanSemanticPath(
|
|
path string,
|
|
) string {
|
|
|
|
if path == "" {
|
|
return "/"
|
|
}
|
|
|
|
if !strings.HasPrefix(path, "/") {
|
|
path = "/" + path
|
|
}
|
|
|
|
if len(path) > 1 &&
|
|
strings.HasSuffix(path, "/") {
|
|
|
|
path = strings.TrimSuffix(
|
|
path,
|
|
"/",
|
|
)
|
|
}
|
|
|
|
return path
|
|
}
|
|
|
|
func parentPath(
|
|
path string,
|
|
) string {
|
|
|
|
path = cleanSemanticPath(path)
|
|
|
|
if path == "/" {
|
|
return "/"
|
|
}
|
|
|
|
idx := strings.LastIndex(path, "/")
|
|
|
|
if idx <= 0 {
|
|
return "/"
|
|
}
|
|
|
|
return path[:idx]
|
|
}
|