mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2024-12-22 03:30:37 +00:00
refactor(erigon-lib/metrics): replace strings.IndexByte with strings.Cut (#9202)
above go1.18 Index calls are more clearly written using Cut. https://github.com/golang/go/issues/46336
This commit is contained in:
parent
fa1e1bab27
commit
db1dcbb9d7
@ -12,25 +12,24 @@ func parseMetric(s string) (string, prometheus.Labels, error) {
|
||||
if len(s) == 0 {
|
||||
return "", nil, fmt.Errorf("metric cannot be empty")
|
||||
}
|
||||
n := strings.IndexByte(s, '{')
|
||||
if n < 0 {
|
||||
|
||||
ident, rest, ok := strings.Cut(s, "{")
|
||||
if !ok {
|
||||
if err := validateIdent(s); err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
|
||||
return s, nil, nil
|
||||
}
|
||||
ident := s[:n]
|
||||
s = s[n+1:]
|
||||
|
||||
if err := validateIdent(ident); err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
if len(s) == 0 || s[len(s)-1] != '}' {
|
||||
|
||||
if len(rest) == 0 || rest[len(rest)-1] != '}' {
|
||||
return "", nil, fmt.Errorf("missing closing curly brace at the end of %q", ident)
|
||||
}
|
||||
|
||||
tags, err := parseTags(s[:len(s)-1])
|
||||
|
||||
tags, err := parseTags(rest[:len(rest)-1])
|
||||
if err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user