mirror of https://github.com/prometheus/prometheus
labels: add string constructor, expose matcher
parent
787199a88e
commit
0d0c5cfaf1
|
@ -87,3 +87,17 @@ func FromMap(m map[string]string) Labels {
|
||||||
}
|
}
|
||||||
return New(l...)
|
return New(l...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FromStrings creates new labels from pairs of strings.
|
||||||
|
func FromStrings(ss ...string) Labels {
|
||||||
|
if len(ss)%2 != 0 {
|
||||||
|
panic("invalid number of strings")
|
||||||
|
}
|
||||||
|
var res Labels
|
||||||
|
for i := 0; i < len(ss); i += 2 {
|
||||||
|
res = append(res, Label{Name: ss[i], Value: ss[i+1]})
|
||||||
|
}
|
||||||
|
|
||||||
|
sort.Sort(res)
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
|
|
@ -23,16 +23,16 @@ type Matcher interface {
|
||||||
Matches(v string) bool
|
Matches(v string) bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type equalMatcher struct {
|
type EqualMatcher struct {
|
||||||
name, value string
|
LabelName, Value string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *equalMatcher) Name() string { return m.name }
|
func (m *EqualMatcher) Name() string { return m.LabelName }
|
||||||
func (m *equalMatcher) Matches(v string) bool { return v == m.value }
|
func (m *EqualMatcher) Matches(v string) bool { return v == m.Value }
|
||||||
|
|
||||||
// NewEqualMatcher returns a new matcher matching an exact label value.
|
// NewEqualMatcher returns a new matcher matching an exact label value.
|
||||||
func NewEqualMatcher(name, value string) Matcher {
|
func NewEqualMatcher(name, value string) Matcher {
|
||||||
return &equalMatcher{name: name, value: value}
|
return &EqualMatcher{LabelName: name, Value: value}
|
||||||
}
|
}
|
||||||
|
|
||||||
type regexpMatcher struct {
|
type regexpMatcher struct {
|
||||||
|
|
Loading…
Reference in New Issue