github.com/artisanhe/tools@v1.0.1-0.20210607022958-19a8fef2eb04/catgo/cat-go/cat/metric_helper.go (about) 1 package cat 2 3 import ( 4 "time" 5 ) 6 7 type MetricHelper interface { 8 AddTag(key, val string) MetricHelper 9 Count(int) 10 Duration(time.Duration) 11 } 12 13 type catMetricHelper struct { 14 name string 15 tags map[string]string 16 } 17 18 type nullMetricHelper struct { 19 } 20 21 func (h *nullMetricHelper) AddTag(key, val string) MetricHelper { 22 return h 23 } 24 25 func (h *nullMetricHelper) Count(count int) { 26 } 27 28 func (h *nullMetricHelper) Duration(duration time.Duration) { 29 } 30 31 func newMetricHelper(name string) MetricHelper { 32 return &catMetricHelper{ 33 name: name, 34 tags: make(map[string]string), 35 } 36 } 37 38 func (h *catMetricHelper) AddTag(key, val string) MetricHelper { 39 h.tags[key] = val 40 return h 41 } 42 43 func (h *catMetricHelper) Count(count int) { 44 aggregator.metric.AddCount(h.name, count) 45 } 46 47 func (h *catMetricHelper) Duration(duration time.Duration) { 48 aggregator.metric.AddDuration(h.name, duration) 49 }