34 lines
575 B
Go
34 lines
575 B
Go
package tower
|
|
|
|
import "strings"
|
|
|
|
func normalizePath(path string) string {
|
|
if path == "" {
|
|
return "/"
|
|
}
|
|
|
|
path = strings.TrimLeft(path, "/")
|
|
path = strings.TrimRight(path, "/")
|
|
|
|
return "/" + path
|
|
}
|
|
|
|
func buildFullPath(prefix string, path string) string {
|
|
normalizedPrefix := normalizePath(prefix)
|
|
normalizedPath := normalizePath(path)
|
|
|
|
if normalizedPrefix == "/" && normalizedPath == "/" {
|
|
return "/"
|
|
}
|
|
|
|
if normalizedPrefix == "/" {
|
|
return normalizedPath
|
|
}
|
|
|
|
if normalizedPath == "/" {
|
|
return normalizedPrefix
|
|
}
|
|
|
|
return normalizedPrefix + normalizedPath
|
|
}
|