-
Notifications
You must be signed in to change notification settings - Fork 0
/
metrics.go
40 lines (38 loc) · 1 KB
/
metrics.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
//go:generate protoc -I=. -I=$GOPATH/src -I=$GOPATH/src/github.com/Dharitri-org/protobuf/protobuf --gogoslick_out=. metrics.proto
package metrics
// ListFromMap returns a list of values from the provided map
func ListFromMap(metricsMap map[string]interface{}) *MetricsList {
r := &MetricsList{
Metrics: make([]Metric, 0, len(metricsMap)),
}
for key, value := range metricsMap {
m := Metric{
Key: key,
}
switch v := value.(type) {
case uint64:
m.Value = &Metric_ValUint64{ValUint64: v}
case string:
m.Value = &Metric_ValString{ValString: v}
default:
continue
}
r.Metrics = append(r.Metrics, m)
}
return r
}
// MapFromList returns a map with the values from the list
func MapFromList(l *MetricsList) map[string]interface{} {
ret := make(map[string]interface{}, len(l.Metrics))
for _, m := range l.Metrics {
switch v := m.Value.(type) {
case *Metric_ValUint64:
ret[m.Key] = v.ValUint64
case *Metric_ValString:
ret[m.Key] = v.ValString
default:
continue
}
}
return ret
}