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

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