-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathrequest_type.go
175 lines (154 loc) · 3.81 KB
/
request_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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
package cloudwatch
import (
"time"
SDK "github.com/aws/aws-sdk-go/service/cloudwatch"
"github.com/evalphobia/aws-sdk-go-wrapper/private/pointers"
)
type MetricStatisticsInput struct {
StartTime time.Time
EndTime time.Time
Period int64
MetricName string
Namespace string
Unit string
Statistics []string
ExtendedStatistics []string
Dimensions []Dimension
// Key: Dimension.Name, Value: Dimension.Value.
// If you use same key and differenct values, then use Dimensions.
DimensionsMap map[string]string
}
func (o MetricStatisticsInput) ToInput() *SDK.GetMetricStatisticsInput {
in := &SDK.GetMetricStatisticsInput{}
if !o.StartTime.IsZero() {
in.StartTime = &o.StartTime
}
if !o.EndTime.IsZero() {
in.EndTime = &o.EndTime
}
if o.Period != 0 {
in.Period = &o.Period
}
if o.MetricName != "" {
in.MetricName = &o.MetricName
}
if o.Namespace != "" {
in.Namespace = &o.Namespace
}
if o.Unit != "" {
in.Unit = &o.Unit
}
in.Statistics = pointers.SliceString(o.Statistics)
in.ExtendedStatistics = pointers.SliceString(o.ExtendedStatistics)
in.Dimensions = make([]*SDK.Dimension, 0, len(o.DimensionsMap)+len(o.Dimensions))
for key, val := range o.DimensionsMap {
in.Dimensions = append(in.Dimensions, &SDK.Dimension{
Name: pointers.String(key),
Value: pointers.String(val),
})
}
for _, v := range o.Dimensions {
in.Dimensions = append(in.Dimensions, &SDK.Dimension{
Name: pointers.String(v.Name),
Value: pointers.String(v.Value),
})
}
return in
}
type Dimension struct {
Name string
Value string
}
type PutMetricDataInput struct {
MetricData []MetricDatum
Namespace string
}
func (o *PutMetricDataInput) AddMetric(d MetricDatum) {
o.MetricData = append(o.MetricData, d)
}
func (o PutMetricDataInput) ToInput() *SDK.PutMetricDataInput {
in := &SDK.PutMetricDataInput{}
if o.Namespace != "" {
in.Namespace = &o.Namespace
}
in.MetricData = make([]*SDK.MetricDatum, 0, len(o.MetricData))
for _, v := range o.MetricData {
in.MetricData = append(in.MetricData, v.ToSDKValue())
}
return in
}
type MetricDatum struct {
MetricName string
Unit string
StorageResolution int64
Value float64
HasValue bool // use as true when value == 0
Values []float64
Counts []float64
Timestamp time.Time
StatisticValues StatisticSet
Dimensions []Dimension
}
func (d MetricDatum) ToSDKValue() *SDK.MetricDatum {
in := &SDK.MetricDatum{}
if d.MetricName != "" {
in.MetricName = &d.MetricName
}
if d.Unit != "" {
in.Unit = &d.Unit
}
if d.StorageResolution != 0 {
in.StorageResolution = &d.StorageResolution
}
if d.HasValue || d.Value != 0 {
in.Value = &d.Value
}
in.Values = pointers.SliceFloat64(d.Values)
in.Counts = pointers.SliceFloat64(d.Counts)
if !d.Timestamp.IsZero() {
in.Timestamp = &d.Timestamp
}
in.StatisticValues = d.StatisticValues.ToSDKValue()
for _, v := range d.Dimensions {
in.Dimensions = append(in.Dimensions, &SDK.Dimension{
Name: pointers.String(v.Name),
Value: pointers.String(v.Value),
})
}
return in
}
type StatisticSet struct {
Maximum float64
Minimum float64
SampleCount float64
Sum float64
// use as true when value == 0
HasMaximum bool
HasMinimum bool
HasSampleCount bool
HasSum bool
}
func (d StatisticSet) ToSDKValue() *SDK.StatisticSet {
hasValue := false
in := &SDK.StatisticSet{}
if d.HasMaximum || d.Maximum != 0 {
in.Maximum = &d.Maximum
hasValue = true
}
if d.HasMinimum || d.Minimum != 0 {
in.Minimum = &d.Minimum
hasValue = true
}
if d.HasSampleCount || d.SampleCount != 0 {
in.SampleCount = &d.SampleCount
hasValue = true
}
if d.HasSum || d.Sum != 0 {
in.Sum = &d.Sum
hasValue = true
}
if !hasValue {
return nil
}
return in
}