aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHana Kim <hyangah@gmail.com>2026-03-05 22:47:31 -0500
committerHyang-Ah Hana Kim <hyangah@gmail.com>2026-03-26 14:11:32 -0700
commit98258ff769bbca6f3d004ce80fabf5bff8f1136c (patch)
tree1ff3dccebdfc2df17009088688a1575383f68a42
parent34edebc0803b121acd1cbf363eef074e0a13ab6d (diff)
downloadgo-x-pkgsite-98258ff769bbca6f3d004ce80fabf5bff8f1136c.tar.xz
all: run go fix -slicescontains
Change-Id: I14479d9e612dfa7eed9188206746af5b51c10201 Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/753428 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Jonathan Amsterdam <jba@google.com> kokoro-CI: kokoro <noreply+kokoro@google.com>
-rw-r--r--internal/godoc/dochtml/internal/render/linkify_test.go6
-rw-r--r--internal/middleware/accept_requests.go9
-rw-r--r--internal/middleware/caching.go9
-rw-r--r--internal/middleware/quota.go13
-rw-r--r--internal/postgres/search.go8
-rw-r--r--internal/postgres/symbolsearch.go7
-rw-r--r--internal/source/source.go9
-rw-r--r--internal/stdlib/stdlib.go7
-rw-r--r--internal/testing/htmlcheck/query.go7
-rw-r--r--internal/vuln/client.go6
10 files changed, 31 insertions, 50 deletions
diff --git a/internal/godoc/dochtml/internal/render/linkify_test.go b/internal/godoc/dochtml/internal/render/linkify_test.go
index 612740cb..c6627ec8 100644
--- a/internal/godoc/dochtml/internal/render/linkify_test.go
+++ b/internal/godoc/dochtml/internal/render/linkify_test.go
@@ -181,10 +181,8 @@ func declForName(t *testing.T, pkg *doc.Package, symbol string) ast.Decl {
inVals := func(vals []*doc.Value) ast.Decl {
for _, v := range vals {
- for _, n := range v.Names {
- if n == symbol {
- return v.Decl
- }
+ if slices.Contains(v.Names, symbol) {
+ return v.Decl
}
}
return nil
diff --git a/internal/middleware/accept_requests.go b/internal/middleware/accept_requests.go
index 5e484644..8d933a4d 100644
--- a/internal/middleware/accept_requests.go
+++ b/internal/middleware/accept_requests.go
@@ -6,6 +6,7 @@ package middleware
import (
"net/http"
+ "slices"
)
const maxURILength = 1000
@@ -20,11 +21,9 @@ func AcceptRequests(methods ...string) Middleware {
http.Error(w, http.StatusText(http.StatusRequestURITooLong), http.StatusRequestURITooLong)
return
}
- for _, m := range methods {
- if r.Method == m {
- h.ServeHTTP(w, r)
- return
- }
+ if slices.Contains(methods, r.Method) {
+ h.ServeHTTP(w, r)
+ return
}
http.Error(w, http.StatusText(http.StatusMethodNotAllowed), http.StatusMethodNotAllowed)
})
diff --git a/internal/middleware/caching.go b/internal/middleware/caching.go
index 32cb0a87..b88c2a24 100644
--- a/internal/middleware/caching.go
+++ b/internal/middleware/caching.go
@@ -11,6 +11,7 @@ import (
"fmt"
"io"
"net/http"
+ "slices"
"strconv"
"time"
@@ -137,11 +138,9 @@ func (c *cacher) Cache(name string, expirer func(r *http.Request) time.Duration,
func (c *cache) ServeHTTP(w http.ResponseWriter, r *http.Request) {
// Check auth header to see if request should bypass cache.
authVal := r.Header.Get(config.BypassCacheAuthHeader)
- for _, wantVal := range c.authValues {
- if authVal == wantVal {
- c.delegate.ServeHTTP(w, r)
- return
- }
+ if slices.Contains(c.authValues, authVal) {
+ c.delegate.ServeHTTP(w, r)
+ return
}
// If the flash cookie is set, bypass the cache.
if _, err := r.Cookie(cookie.AlternativeModuleFlash); err == nil {
diff --git a/internal/middleware/quota.go b/internal/middleware/quota.go
index 70bde537..c903bd17 100644
--- a/internal/middleware/quota.go
+++ b/internal/middleware/quota.go
@@ -12,6 +12,7 @@ import (
"io"
"net"
"net/http"
+ "slices"
"strings"
"time"
@@ -78,13 +79,11 @@ func Quota(settings config.QuotaSettings, client *redis.Client) Middleware {
return
}
authVal := r.Header.Get(config.BypassQuotaAuthHeader)
- for _, wantVal := range settings.AuthValues {
- if authVal == wantVal {
- recordQuotaMetric(ctx, "bypassed")
- log.Infof(ctx, "Quota: accepting %q", authVal)
- h.ServeHTTP(w, r)
- return
- }
+ if slices.Contains(settings.AuthValues, authVal) {
+ recordQuotaMetric(ctx, "bypassed")
+ log.Infof(ctx, "Quota: accepting %q", authVal)
+ h.ServeHTTP(w, r)
+ return
}
header := r.Header.Get("X-Godoc-Forwarded-For")
if header == "" {
diff --git a/internal/postgres/search.go b/internal/postgres/search.go
index bdc2c30d..f9ab60de 100644
--- a/internal/postgres/search.go
+++ b/internal/postgres/search.go
@@ -8,6 +8,7 @@ import (
"context"
"database/sql"
"fmt"
+ "slices"
"sort"
"strings"
"time"
@@ -1006,12 +1007,7 @@ func GeneratePathTokens(packagePath string) []string {
// isInternalPackage reports whether the path represents an internal directory.
func isInternalPackage(path string) bool {
- for _, p := range strings.Split(path, "/") {
- if p == "internal" {
- return true
- }
- }
- return false
+ return slices.Contains(strings.Split(path, "/"), "internal")
}
// UpsertSearchDocumentWithImportedByCount is the same as UpsertSearchDocument,
diff --git a/internal/postgres/symbolsearch.go b/internal/postgres/symbolsearch.go
index f1a273e6..9373c92c 100644
--- a/internal/postgres/symbolsearch.go
+++ b/internal/postgres/symbolsearch.go
@@ -9,6 +9,7 @@ import (
"database/sql"
"errors"
"fmt"
+ "slices"
"sort"
"strings"
@@ -299,12 +300,10 @@ func splitPackageAndSymbolNames(q string) (pkgName string, symbolName string, er
if len(parts) != 2 && len(parts) != 3 {
return "", "", derrors.NotFound
}
- for _, p := range parts {
+ if slices.Contains(parts, "") {
// Handle cases where we have odd dot placement, such as .Foo or
// Foo..
- if p == "" {
- return "", "", derrors.NotFound
- }
+ return "", "", derrors.NotFound
}
return parts[0], strings.Join(parts[1:], "."), nil
}
diff --git a/internal/source/source.go b/internal/source/source.go
index 8c3d340c..b30ccc3b 100644
--- a/internal/source/source.go
+++ b/internal/source/source.go
@@ -28,6 +28,7 @@ import (
"path"
"path/filepath"
"regexp"
+ "slices"
"strconv"
"strings"
@@ -748,13 +749,7 @@ func init() {
for i := range patterns {
re := regexp.MustCompile(patterns[i].pattern)
// The pattern regexp must contain a group named "repo".
- found := false
- for _, n := range re.SubexpNames() {
- if n == "repo" {
- found = true
- break
- }
- }
+ found := slices.Contains(re.SubexpNames(), "repo")
if !found {
panic(fmt.Sprintf("pattern %s missing <repo> group", patterns[i].pattern))
}
diff --git a/internal/stdlib/stdlib.go b/internal/stdlib/stdlib.go
index 1579f83a..c151febd 100644
--- a/internal/stdlib/stdlib.go
+++ b/internal/stdlib/stdlib.go
@@ -20,6 +20,7 @@ import (
"path"
"path/filepath"
"regexp"
+ "slices"
"strings"
"sync"
"time"
@@ -458,10 +459,8 @@ func semanticVersion(requestedVersion string) (_ string, err error) {
}
return latestVersion, nil
default:
- for _, v := range knownVersions {
- if v == requestedVersion {
- return requestedVersion, nil
- }
+ if slices.Contains(knownVersions, requestedVersion) {
+ return requestedVersion, nil
}
}
diff --git a/internal/testing/htmlcheck/query.go b/internal/testing/htmlcheck/query.go
index 75a196dd..fe594150 100644
--- a/internal/testing/htmlcheck/query.go
+++ b/internal/testing/htmlcheck/query.go
@@ -7,6 +7,7 @@ package htmlcheck
import (
"errors"
"fmt"
+ "slices"
"strconv"
"strings"
@@ -317,10 +318,8 @@ func (s *classSelector) match(n *html.Node) bool {
}
for _, attr := range n.Attr {
if attr.Key == "class" {
- for _, f := range strings.Fields(attr.Val) {
- if f == s.class {
- return true
- }
+ if slices.Contains(strings.Fields(attr.Val), s.class) {
+ return true
}
break
}
diff --git a/internal/vuln/client.go b/internal/vuln/client.go
index 561835dd..63f2da7f 100644
--- a/internal/vuln/client.go
+++ b/internal/vuln/client.go
@@ -175,10 +175,8 @@ func (c *Client) ByAlias(ctx context.Context, alias string) (_ string, err error
return "", err
}
for _, v := range vs {
- for _, vAlias := range v.Aliases {
- if alias == vAlias {
- return v.ID, nil
- }
+ if slices.Contains(v.Aliases, alias) {
+ return v.ID, nil
}
}
return "", derrors.NotFound