kra-new/internal/utils/routepath/routepath.go

20 lines
492 B
Go

package routepath
import "strings"
// Normalize removes only a complete configured router prefix. Paths
// such as /administrator must not be shortened when the prefix is /admin.
func Normalize(path, routerPrefix string) string {
prefix := strings.TrimSuffix(strings.TrimSpace(routerPrefix), "/")
if prefix == "" || prefix == "/" {
return path
}
if path == prefix {
return "/"
}
if strings.HasPrefix(path, prefix+"/") {
return strings.TrimPrefix(path, prefix)
}
return path
}