Skip to content

Commit 3328d4d

Browse files
authored
Apply the stringscutprefix modernizer (#1051)
The stringscutprefix analyzer simplifies a common pattern where code first checks for a prefix with `strings.HasPrefix` and then removes it with `strings.TrimPrefix`. It replaces this two-step process with a single call to `strings.CutPrefix`, introduced in Go 1.20. The analyzer also handles the equivalent functions in the `bytes` package. See https://pkg.go.dev/golang.org/x/tools/go/analysis/passes/modernize#hdr-Analyzer_stringscutprefix
1 parent be60b2e commit 3328d4d

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

‎middleware/compress.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ func NewCompressor(level int, types ...string) *Compressor {
7070
if strings.Contains(strings.TrimSuffix(t, "/*"), "*") {
7171
panic(fmt.Sprintf("middleware/compress: Unsupported content-type wildcard pattern '%s'. Only '/*' supported", t))
7272
}
73-
if strings.HasSuffix(t, "/*") {
74-
allowedWildcards[strings.TrimSuffix(t, "/*")] = struct{}{}
73+
if before, ok := strings.CutSuffix(t, "/*"); ok {
74+
allowedWildcards[before] = struct{}{}
7575
} else {
7676
allowedTypes[t] = struct{}{}
7777
}

0 commit comments

Comments
 (0)