-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtag_opt.go
More file actions
39 lines (33 loc) · 953 Bytes
/
tag_opt.go
File metadata and controls
39 lines (33 loc) · 953 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package stats
// TagExtractStrategy represents the extract strategy from metric for dynamic tags.
type TagExtractStrategy struct {
Name string
Regex string
SubStr string
}
// TagOption controls how tags are set.
type TagOption struct {
DefaultTags map[string]string
TagExtractStrategies []TagExtractStrategy
}
// NewTagOption creates an empty TagOption.
func NewTagOption() *TagOption {
return &TagOption{}
}
func (t TagOption) defaultTags() []*Tag {
var tags = make([]*Tag, 0, len(t.DefaultTags))
for k, v := range t.DefaultTags {
tags = append(tags, &Tag{k, v})
}
return tags
}
// WithDefaultTags sets default tags.
func (t *TagOption) WithDefaultTags(tags map[string]string) *TagOption {
t.DefaultTags = tags
return t
}
// WithTagExtractStrategies sets tag extract strategies.
func (t *TagOption) WithTagExtractStrategies(strategies ...TagExtractStrategy) *TagOption {
t.TagExtractStrategies = strategies
return t
}