From ebed7fa5b4452e24cb5e769d807f807c983cd338 Mon Sep 17 00:00:00 2001 From: Michael Mayer Date: Tue, 25 Nov 2025 14:26:29 +0100 Subject: [PATCH] Go: Replace strings.Split() with strings.SplitSeq() #5337 Signed-off-by: Michael Mayer --- pkg/fs/ext_list.go | 6 ++---- pkg/http/dns/domain.go | 3 +-- pkg/http/header/auth.go | 4 ++-- pkg/txt/title.go | 5 ++--- 4 files changed, 7 insertions(+), 11 deletions(-) diff --git a/pkg/fs/ext_list.go b/pkg/fs/ext_list.go index 6d3c3fa31..3b70ed417 100644 --- a/pkg/fs/ext_list.go +++ b/pkg/fs/ext_list.go @@ -67,10 +67,8 @@ func (b ExtList) Set(extensions string) { return } - ext := strings.Split(extensions, ",") - - for i := range ext { - b.Add(ext[i]) + for ext := range strings.SplitSeq(extensions, ",") { + b.Add(ext) } } diff --git a/pkg/http/dns/domain.go b/pkg/http/dns/domain.go index fee37e9ed..226aefe21 100644 --- a/pkg/http/dns/domain.go +++ b/pkg/http/dns/domain.go @@ -22,8 +22,7 @@ func IsDomain(d string) bool { if IsLocalSuffix(d) { return false } - parts := strings.Split(d, ".") - for _, p := range parts { + for p := range strings.SplitSeq(d, ".") { if !IsLabel(p) { return false } diff --git a/pkg/http/header/auth.go b/pkg/http/header/auth.go index 0d3664c61..fd80dd0a6 100644 --- a/pkg/http/header/auth.go +++ b/pkg/http/header/auth.go @@ -60,10 +60,10 @@ func Authorization(c *gin.Context) (authType, authToken string) { return "", "" } else if s := c.GetHeader(Auth); s == "" { // Ignore. - } else if t := strings.Split(s, " "); len(t) != 2 { + } else if typ, token, ok := strings.Cut(s, " "); !ok { // Ignore. } else { - return ID(t[0]), ID(t[1]) + return ID(typ), ID(token) } return "", "" diff --git a/pkg/txt/title.go b/pkg/txt/title.go index f77430e40..bc8ed864a 100644 --- a/pkg/txt/title.go +++ b/pkg/txt/title.go @@ -14,10 +14,9 @@ func Title(s string) string { return "" } - blocks := strings.Split(s, "/") - result := make([]string, 0, len(blocks)) + result := make([]string, 0, 4) - for _, block := range blocks { + for block := range strings.SplitSeq(s, "/") { words := strings.Fields(block) if len(words) == 0 {