all: use Go 1.18's strings.Cut

More remain.

Change-Id: I6ec562cc1f687600758deae1c9d7dbd0d04004cb
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
Brad Fitzpatrick
2022-03-16 14:25:31 -07:00
committed by Brad Fitzpatrick
parent 1f22507c06
commit 61ee72940c
7 changed files with 17 additions and 31 deletions
+2 -11
View File
@@ -145,19 +145,10 @@ func AcceptsEncoding(r *http.Request, enc string) bool {
}
remain := h
for len(remain) > 0 {
comma := strings.Index(remain, ",")
var part string
if comma == -1 {
part = remain
remain = ""
} else {
part = remain[:comma]
remain = remain[comma+1:]
}
part, remain, _ = strings.Cut(remain, ",")
part = strings.TrimSpace(part)
if i := strings.Index(part, ";"); i != -1 {
part = part[:i]
}
part, _, _ = strings.Cut(part, ";")
if part == enc {
return true
}
+3 -5
View File
@@ -370,8 +370,8 @@ func writePromExpVar(w io.Writer, prefix string, kv expvar.KeyValue) {
}
if strings.HasPrefix(key, "labelmap_") {
key = strings.TrimPrefix(key, "labelmap_")
if i := strings.Index(key, "_"); i != -1 {
label, key = key[:i], key[i+1:]
if a, b, ok := strings.Cut(key, "_"); ok {
label, key = a, b
}
}
name := prefix + key
@@ -541,9 +541,7 @@ func foreachExportedStructField(rv reflect.Value, f func(fieldOrJSONName, metric
sf := t.Field(i)
name := sf.Name
if v := sf.Tag.Get("json"); v != "" {
if i := strings.Index(v, ","); i != -1 {
v = v[:i]
}
v, _, _ = strings.Cut(v, ",")
if v == "-" {
// Skip it, regardless of its metrictype.
continue