/
helpers.go
57 lines (50 loc) · 911 Bytes
/
helpers.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
package awsfetch
import (
"context"
"strings"
)
func getBoolFromContext(ctx context.Context, key string) bool {
v, ok := ctx.Value(key).(bool)
return v && ok
}
func sliceOfSlice(in []*string, maxLength int) (res [][]*string) {
if maxLength <= 0 {
return
}
if len(in) == 0 {
return
}
for i := 0; i < len(in); i += maxLength {
if i+maxLength < len(in) {
res = append(res, in[i:i+maxLength])
} else {
res = append(res, in[i:])
}
}
return
}
func appendIfNotInSlice(slice []string, s string) []string {
var found bool
for _, e := range slice {
if e == s {
found = true
}
}
if !found {
return append(slice, s)
}
return slice
}
func arnToName(arn string) string {
splits := strings.Split(arn, "/")
if len(splits) > 1 {
return splits[len(splits)-1]
}
return arn
}
func pluralizeIfNeeded(str string, n uint) string {
if n > 1 {
return str + "s"
}
return str
}