提交 0d0c5cfa 编写于 作者: F Fabian Reinartz

labels: add string constructor, expose matcher

上级 787199a8
...@@ -87,3 +87,17 @@ func FromMap(m map[string]string) Labels { ...@@ -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 { ...@@ -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 {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册