-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
util.go
110 lines (101 loc) · 2.41 KB
/
util.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
package main
import (
cwe "github.com/aws/aws-sdk-go/service/cloudwatchevents"
)
// CompareString do compare strings
// nil and empty string are same value
// "" == "" => true
// nil == "" => true
// nil == nil => true
func CompareString(a, b *string) bool {
if a == nil || *a == "" {
if b == nil || *b == "" {
return true
}
return false
} else if b == nil || *b == "" {
if a == nil || *a == "" {
return true
}
return false
}
return *a == *b
}
// CompareInt64 do compare Int64
// 1 == 1 => true
// 1 == 2 => false
// 1 == nil => false
// nil == nil => true
func CompareInt64(a, b *int64) bool {
if a == nil {
if b == nil {
return true
}
return false
} else if b == nil {
return false
}
return *a == *b
}
// CompareKinesisParameters do compare KinesisParameters and cloudwatchevents.KinesisParameters
func CompareKinesisParameters(own *KinesisParameters, theirs *cwe.KinesisParameters) bool {
if theirs == nil {
if own.PartitionKeyPath == "" {
return true
}
} else {
if CompareString(&own.PartitionKeyPath, theirs.PartitionKeyPath) {
return true
}
}
return false
}
// CompareEcsParameters do compare EcsParameters and cloudwatchevents.EcsParameters
func CompareEcsParameters(own *EcsParameters, theirs *cwe.EcsParameters) bool {
if theirs == nil {
if own.TaskDefinitionArn == "" && own.TaskCount == 0 {
return true
}
} else {
if CompareString(&own.TaskDefinitionArn, theirs.TaskDefinitionArn) &&
CompareInt64(&own.TaskCount, theirs.TaskCount) {
return true
}
}
return false
}
// DeleteRuleFromSlice return ClowdWatchEvent Rules that deleted specified index rule.
func DeleteRuleFromSlice(src []*cwe.Rule, deleteIndex int) []*cwe.Rule {
dest := []*cwe.Rule{}
for i, rule := range src {
if i != deleteIndex {
dest = append(dest, rule)
}
}
return dest
}
// DeleteTargetFromSlice return ClowdWatchEvent Targets that deleted specified index target.
func DeleteTargetFromSlice(src []*cwe.Target, deleteIndex int) []*cwe.Target {
dest := []*cwe.Target{}
for i, target := range src {
if i != deleteIndex {
dest = append(dest, target)
}
}
return dest
}
// NilOrStringPtr return string pointer if str is not empty
// if str is empty ("") retuen nil
func NilOrStringPtr(str string) *string {
if str == "" {
return nil
}
return &str
}
// NilSafeStr retuen empty string or passed string
func NilSafeStr(str *string) string {
if str == nil {
return ""
}
return *str
}