Merge pull request #4470 from kolyshkin/strings-cut

Use strings.Cut and strings.CutPrefix where possible
This commit is contained in:
Kir Kolyshkin
2025-02-12 23:35:20 -08:00
committed by GitHub
17 changed files with 97 additions and 109 deletions
+3 -3
View File
@@ -77,7 +77,7 @@ func stripRoot(root, path string) string {
path = "/"
case root == "/":
// do nothing
case strings.HasPrefix(path, root+"/"):
default:
path = strings.TrimPrefix(path, root+"/")
}
return CleanPath("/" + path)
@@ -88,8 +88,8 @@ func stripRoot(root, path string) string {
func SearchLabels(labels []string, key string) (string, bool) {
key += "="
for _, s := range labels {
if strings.HasPrefix(s, key) {
return s[len(key):], true
if val, ok := strings.CutPrefix(s, key); ok {
return val, true
}
}
return "", false