github.com/qxnw/lib4go@v0.0.0-20180426074627-c80c7e84b925/influxdb/models/statistic.go (about) 1 package models 2 3 // Statistic is the representation of a statistic used by the monitoring service. 4 type Statistic struct { 5 Name string `json:"name"` 6 Tags map[string]string `json:"tags"` 7 Values map[string]interface{} `json:"values"` 8 } 9 10 // NewStatistic returns an initialized Statistic. 11 func NewStatistic(name string) Statistic { 12 return Statistic{ 13 Name: name, 14 Tags: make(map[string]string), 15 Values: make(map[string]interface{}), 16 } 17 } 18 19 // StatisticTags is a map that can be merged with others without causing 20 // mutations to either map. 21 type StatisticTags map[string]string 22 23 // Merge creates a new map containing the merged contents of tags and t. 24 // If both tags and the receiver map contain the same key, the value in tags 25 // is used in the resulting map. 26 // 27 // Merge always returns a usable map. 28 func (t StatisticTags) Merge(tags map[string]string) map[string]string { 29 // Add everything in tags to the result. 30 out := make(map[string]string, len(tags)) 31 for k, v := range tags { 32 out[k] = v 33 } 34 35 // Only add values from t that don't appear in tags. 36 for k, v := range t { 37 if _, ok := tags[k]; !ok { 38 out[k] = v 39 } 40 } 41 return out 42 }