-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmetric_builder.go
61 lines (44 loc) · 1.11 KB
/
metric_builder.go
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package nlog_4go
import "github.com/bingzhilanmo-bowen/mylog-4go/nlog"
type Builder interface {
Metric(metricName string) Builder
Tags(key, value string) Builder
TagsOnFly(key, value string) Builder
Build() *nlog.MetricName
}
type MetricNameBuilder struct {
metric *nlog.MetricName
}
func NewMetricBuilder() *MetricNameBuilder {
return &MetricNameBuilder{metric:&nlog.MetricName{}}
}
func (m *MetricNameBuilder) Metric(metricName string) Builder {
if m.metric == nil {
m.metric = &nlog.MetricName{}
}
m.metric.Metric = metricName
return m
}
func (m *MetricNameBuilder) Tags(key, value string) Builder {
if m.metric == nil {
m.metric = &nlog.MetricName{}
}
if m.metric.Tags == nil {
m.metric.Tags = make(map[string]string, 8)
}
m.metric.Tags[key] = value
return m
}
func (m *MetricNameBuilder) TagsOnFly(key, value string) Builder {
if m.metric == nil {
m.metric = &nlog.MetricName{}
}
if m.metric.TagsOnFly == nil {
m.metric.TagsOnFly = make(map[string]string, 8)
}
m.metric.TagsOnFly[key] = value
return m
}
func (m *MetricNameBuilder) Build() *nlog.MetricName {
return m.metric
}