wisski-cloud-distillery/pkg/mux/path.go
2023-01-11 14:34:04 +01:00

28 lines
595 B
Go

package mux
import (
"path"
)
// NormalizePath normalizes the provided path.
// It ensures that there is both a leading and trailing slash.
func NormalizePath(value string) string {
value = path.Clean(value)
if value != "/" {
value = value + "/"
}
return value
}
// parentSegment returns the parent segment of the provided path
// it assumes that normalizePath has been called on value.
func parentSegment(value string) string {
if value == "" || value == "/" {
return "/"
}
parent := path.Dir(value[:len(value)-1])
if parent != "/" {
parent = parent + "/"
}
return parent
}