]>
Commit | Line | Data |
---|---|---|
bae9f6d2 JC |
1 | package aws |
2 | ||
3 | import "time" | |
4 | ||
5 | // String returns a pointer to the string value passed in. | |
6 | func String(v string) *string { | |
7 | return &v | |
8 | } | |
9 | ||
10 | // StringValue returns the value of the string pointer passed in or | |
11 | // "" if the pointer is nil. | |
12 | func StringValue(v *string) string { | |
13 | if v != nil { | |
14 | return *v | |
15 | } | |
16 | return "" | |
17 | } | |
18 | ||
19 | // StringSlice converts a slice of string values into a slice of | |
20 | // string pointers | |
21 | func StringSlice(src []string) []*string { | |
22 | dst := make([]*string, len(src)) | |
23 | for i := 0; i < len(src); i++ { | |
24 | dst[i] = &(src[i]) | |
25 | } | |
26 | return dst | |
27 | } | |
28 | ||
29 | // StringValueSlice converts a slice of string pointers into a slice of | |
30 | // string values | |
31 | func StringValueSlice(src []*string) []string { | |
32 | dst := make([]string, len(src)) | |
33 | for i := 0; i < len(src); i++ { | |
34 | if src[i] != nil { | |
35 | dst[i] = *(src[i]) | |
36 | } | |
37 | } | |
38 | return dst | |
39 | } | |
40 | ||
41 | // StringMap converts a string map of string values into a string | |
42 | // map of string pointers | |
43 | func StringMap(src map[string]string) map[string]*string { | |
44 | dst := make(map[string]*string) | |
45 | for k, val := range src { | |
46 | v := val | |
47 | dst[k] = &v | |
48 | } | |
49 | return dst | |
50 | } | |
51 | ||
52 | // StringValueMap converts a string map of string pointers into a string | |
53 | // map of string values | |
54 | func StringValueMap(src map[string]*string) map[string]string { | |
55 | dst := make(map[string]string) | |
56 | for k, val := range src { | |
57 | if val != nil { | |
58 | dst[k] = *val | |
59 | } | |
60 | } | |
61 | return dst | |
62 | } | |
63 | ||
64 | // Bool returns a pointer to the bool value passed in. | |
65 | func Bool(v bool) *bool { | |
66 | return &v | |
67 | } | |
68 | ||
69 | // BoolValue returns the value of the bool pointer passed in or | |
70 | // false if the pointer is nil. | |
71 | func BoolValue(v *bool) bool { | |
72 | if v != nil { | |
73 | return *v | |
74 | } | |
75 | return false | |
76 | } | |
77 | ||
78 | // BoolSlice converts a slice of bool values into a slice of | |
79 | // bool pointers | |
80 | func BoolSlice(src []bool) []*bool { | |
81 | dst := make([]*bool, len(src)) | |
82 | for i := 0; i < len(src); i++ { | |
83 | dst[i] = &(src[i]) | |
84 | } | |
85 | return dst | |
86 | } | |
87 | ||
88 | // BoolValueSlice converts a slice of bool pointers into a slice of | |
89 | // bool values | |
90 | func BoolValueSlice(src []*bool) []bool { | |
91 | dst := make([]bool, len(src)) | |
92 | for i := 0; i < len(src); i++ { | |
93 | if src[i] != nil { | |
94 | dst[i] = *(src[i]) | |
95 | } | |
96 | } | |
97 | return dst | |
98 | } | |
99 | ||
100 | // BoolMap converts a string map of bool values into a string | |
101 | // map of bool pointers | |
102 | func BoolMap(src map[string]bool) map[string]*bool { | |
103 | dst := make(map[string]*bool) | |
104 | for k, val := range src { | |
105 | v := val | |
106 | dst[k] = &v | |
107 | } | |
108 | return dst | |
109 | } | |
110 | ||
111 | // BoolValueMap converts a string map of bool pointers into a string | |
112 | // map of bool values | |
113 | func BoolValueMap(src map[string]*bool) map[string]bool { | |
114 | dst := make(map[string]bool) | |
115 | for k, val := range src { | |
116 | if val != nil { | |
117 | dst[k] = *val | |
118 | } | |
119 | } | |
120 | return dst | |
121 | } | |
122 | ||
123 | // Int returns a pointer to the int value passed in. | |
124 | func Int(v int) *int { | |
125 | return &v | |
126 | } | |
127 | ||
128 | // IntValue returns the value of the int pointer passed in or | |
129 | // 0 if the pointer is nil. | |
130 | func IntValue(v *int) int { | |
131 | if v != nil { | |
132 | return *v | |
133 | } | |
134 | return 0 | |
135 | } | |
136 | ||
137 | // IntSlice converts a slice of int values into a slice of | |
138 | // int pointers | |
139 | func IntSlice(src []int) []*int { | |
140 | dst := make([]*int, len(src)) | |
141 | for i := 0; i < len(src); i++ { | |
142 | dst[i] = &(src[i]) | |
143 | } | |
144 | return dst | |
145 | } | |
146 | ||
147 | // IntValueSlice converts a slice of int pointers into a slice of | |
148 | // int values | |
149 | func IntValueSlice(src []*int) []int { | |
150 | dst := make([]int, len(src)) | |
151 | for i := 0; i < len(src); i++ { | |
152 | if src[i] != nil { | |
153 | dst[i] = *(src[i]) | |
154 | } | |
155 | } | |
156 | return dst | |
157 | } | |
158 | ||
159 | // IntMap converts a string map of int values into a string | |
160 | // map of int pointers | |
161 | func IntMap(src map[string]int) map[string]*int { | |
162 | dst := make(map[string]*int) | |
163 | for k, val := range src { | |
164 | v := val | |
165 | dst[k] = &v | |
166 | } | |
167 | return dst | |
168 | } | |
169 | ||
170 | // IntValueMap converts a string map of int pointers into a string | |
171 | // map of int values | |
172 | func IntValueMap(src map[string]*int) map[string]int { | |
173 | dst := make(map[string]int) | |
174 | for k, val := range src { | |
175 | if val != nil { | |
176 | dst[k] = *val | |
177 | } | |
178 | } | |
179 | return dst | |
180 | } | |
181 | ||
182 | // Int64 returns a pointer to the int64 value passed in. | |
183 | func Int64(v int64) *int64 { | |
184 | return &v | |
185 | } | |
186 | ||
187 | // Int64Value returns the value of the int64 pointer passed in or | |
188 | // 0 if the pointer is nil. | |
189 | func Int64Value(v *int64) int64 { | |
190 | if v != nil { | |
191 | return *v | |
192 | } | |
193 | return 0 | |
194 | } | |
195 | ||
196 | // Int64Slice converts a slice of int64 values into a slice of | |
197 | // int64 pointers | |
198 | func Int64Slice(src []int64) []*int64 { | |
199 | dst := make([]*int64, len(src)) | |
200 | for i := 0; i < len(src); i++ { | |
201 | dst[i] = &(src[i]) | |
202 | } | |
203 | return dst | |
204 | } | |
205 | ||
206 | // Int64ValueSlice converts a slice of int64 pointers into a slice of | |
207 | // int64 values | |
208 | func Int64ValueSlice(src []*int64) []int64 { | |
209 | dst := make([]int64, len(src)) | |
210 | for i := 0; i < len(src); i++ { | |
211 | if src[i] != nil { | |
212 | dst[i] = *(src[i]) | |
213 | } | |
214 | } | |
215 | return dst | |
216 | } | |
217 | ||
218 | // Int64Map converts a string map of int64 values into a string | |
219 | // map of int64 pointers | |
220 | func Int64Map(src map[string]int64) map[string]*int64 { | |
221 | dst := make(map[string]*int64) | |
222 | for k, val := range src { | |
223 | v := val | |
224 | dst[k] = &v | |
225 | } | |
226 | return dst | |
227 | } | |
228 | ||
229 | // Int64ValueMap converts a string map of int64 pointers into a string | |
230 | // map of int64 values | |
231 | func Int64ValueMap(src map[string]*int64) map[string]int64 { | |
232 | dst := make(map[string]int64) | |
233 | for k, val := range src { | |
234 | if val != nil { | |
235 | dst[k] = *val | |
236 | } | |
237 | } | |
238 | return dst | |
239 | } | |
240 | ||
241 | // Float64 returns a pointer to the float64 value passed in. | |
242 | func Float64(v float64) *float64 { | |
243 | return &v | |
244 | } | |
245 | ||
246 | // Float64Value returns the value of the float64 pointer passed in or | |
247 | // 0 if the pointer is nil. | |
248 | func Float64Value(v *float64) float64 { | |
249 | if v != nil { | |
250 | return *v | |
251 | } | |
252 | return 0 | |
253 | } | |
254 | ||
255 | // Float64Slice converts a slice of float64 values into a slice of | |
256 | // float64 pointers | |
257 | func Float64Slice(src []float64) []*float64 { | |
258 | dst := make([]*float64, len(src)) | |
259 | for i := 0; i < len(src); i++ { | |
260 | dst[i] = &(src[i]) | |
261 | } | |
262 | return dst | |
263 | } | |
264 | ||
265 | // Float64ValueSlice converts a slice of float64 pointers into a slice of | |
266 | // float64 values | |
267 | func Float64ValueSlice(src []*float64) []float64 { | |
268 | dst := make([]float64, len(src)) | |
269 | for i := 0; i < len(src); i++ { | |
270 | if src[i] != nil { | |
271 | dst[i] = *(src[i]) | |
272 | } | |
273 | } | |
274 | return dst | |
275 | } | |
276 | ||
277 | // Float64Map converts a string map of float64 values into a string | |
278 | // map of float64 pointers | |
279 | func Float64Map(src map[string]float64) map[string]*float64 { | |
280 | dst := make(map[string]*float64) | |
281 | for k, val := range src { | |
282 | v := val | |
283 | dst[k] = &v | |
284 | } | |
285 | return dst | |
286 | } | |
287 | ||
288 | // Float64ValueMap converts a string map of float64 pointers into a string | |
289 | // map of float64 values | |
290 | func Float64ValueMap(src map[string]*float64) map[string]float64 { | |
291 | dst := make(map[string]float64) | |
292 | for k, val := range src { | |
293 | if val != nil { | |
294 | dst[k] = *val | |
295 | } | |
296 | } | |
297 | return dst | |
298 | } | |
299 | ||
300 | // Time returns a pointer to the time.Time value passed in. | |
301 | func Time(v time.Time) *time.Time { | |
302 | return &v | |
303 | } | |
304 | ||
305 | // TimeValue returns the value of the time.Time pointer passed in or | |
306 | // time.Time{} if the pointer is nil. | |
307 | func TimeValue(v *time.Time) time.Time { | |
308 | if v != nil { | |
309 | return *v | |
310 | } | |
311 | return time.Time{} | |
312 | } | |
313 | ||
314 | // TimeUnixMilli returns a Unix timestamp in milliseconds from "January 1, 1970 UTC". | |
315 | // The result is undefined if the Unix time cannot be represented by an int64. | |
316 | // Which includes calling TimeUnixMilli on a zero Time is undefined. | |
317 | // | |
318 | // This utility is useful for service API's such as CloudWatch Logs which require | |
319 | // their unix time values to be in milliseconds. | |
320 | // | |
321 | // See Go stdlib https://golang.org/pkg/time/#Time.UnixNano for more information. | |
322 | func TimeUnixMilli(t time.Time) int64 { | |
323 | return t.UnixNano() / int64(time.Millisecond/time.Nanosecond) | |
324 | } | |
325 | ||
326 | // TimeSlice converts a slice of time.Time values into a slice of | |
327 | // time.Time pointers | |
328 | func TimeSlice(src []time.Time) []*time.Time { | |
329 | dst := make([]*time.Time, len(src)) | |
330 | for i := 0; i < len(src); i++ { | |
331 | dst[i] = &(src[i]) | |
332 | } | |
333 | return dst | |
334 | } | |
335 | ||
336 | // TimeValueSlice converts a slice of time.Time pointers into a slice of | |
337 | // time.Time values | |
338 | func TimeValueSlice(src []*time.Time) []time.Time { | |
339 | dst := make([]time.Time, len(src)) | |
340 | for i := 0; i < len(src); i++ { | |
341 | if src[i] != nil { | |
342 | dst[i] = *(src[i]) | |
343 | } | |
344 | } | |
345 | return dst | |
346 | } | |
347 | ||
348 | // TimeMap converts a string map of time.Time values into a string | |
349 | // map of time.Time pointers | |
350 | func TimeMap(src map[string]time.Time) map[string]*time.Time { | |
351 | dst := make(map[string]*time.Time) | |
352 | for k, val := range src { | |
353 | v := val | |
354 | dst[k] = &v | |
355 | } | |
356 | return dst | |
357 | } | |
358 | ||
359 | // TimeValueMap converts a string map of time.Time pointers into a string | |
360 | // map of time.Time values | |
361 | func TimeValueMap(src map[string]*time.Time) map[string]time.Time { | |
362 | dst := make(map[string]time.Time) | |
363 | for k, val := range src { | |
364 | if val != nil { | |
365 | dst[k] = *val | |
366 | } | |
367 | } | |
368 | return dst | |
369 | } |