-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathresponse_type.go
70 lines (61 loc) · 1.46 KB
/
response_type.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
62
63
64
65
66
67
68
69
70
package cloudwatch
import (
"time"
SDK "github.com/aws/aws-sdk-go/service/cloudwatch"
)
type MetricStatisticsResponse struct {
Datapoints []Datapoint
Label string
}
func NewMetricStatisticsResponse(out *SDK.GetMetricStatisticsOutput) *MetricStatisticsResponse {
r := &MetricStatisticsResponse{}
if out.Label != nil {
r.Label = *out.Label
}
if len(out.Datapoints) == 0 {
return r
}
r.Datapoints = make([]Datapoint, len(out.Datapoints))
for i, d := range out.Datapoints {
r.Datapoints[i] = NewDatapoint(d)
}
return r
}
type Datapoint struct {
Average float64
ExtendedStatistics map[string]float64
Maximum float64
Minimum float64
SampleCount float64
Sum float64
Unit string
Timestamp time.Time
}
func NewDatapoint(d *SDK.Datapoint) Datapoint {
dd := Datapoint{}
dd.Average = getFloat64FromPointer(d.Average)
dd.Maximum = getFloat64FromPointer(d.Maximum)
dd.Minimum = getFloat64FromPointer(d.Minimum)
dd.SampleCount = getFloat64FromPointer(d.SampleCount)
if d.Sum != nil {
dd.Sum = *d.Sum
}
if d.Unit != nil {
dd.Unit = *d.Unit
}
if d.Timestamp != nil {
dd.Timestamp = *d.Timestamp
}
s := make(map[string]float64, len(d.ExtendedStatistics))
for key, val := range d.ExtendedStatistics {
s[key] = getFloat64FromPointer(val)
}
dd.ExtendedStatistics = s
return dd
}
func getFloat64FromPointer(v *float64) float64 {
if v != nil {
return *v
}
return 0.0
}