2019-07-21 19:58:19 +02:00
|
|
|
package util
|
2015-07-14 22:51:12 +02:00
|
|
|
|
2019-07-21 22:22:30 +02:00
|
|
|
// SliceEqual compares two slices and checks whether they have equal content
|
2019-07-21 19:58:19 +02:00
|
|
|
func SliceEqual(s1, s2 []string) bool {
|
2015-07-14 22:51:12 +02:00
|
|
|
if len(s1) != len(s2) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
for i := range s1 {
|
|
|
|
if s1[i] != s2[i] {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2019-07-21 22:22:30 +02:00
|
|
|
// SliceSubtract subtracts the content of slice a2 from slice a1
|
2019-07-21 19:58:19 +02:00
|
|
|
func SliceSubtract(a1, a2 []string) []string {
|
2015-07-14 22:51:12 +02:00
|
|
|
a := []string{}
|
|
|
|
|
|
|
|
for _, e1 := range a1 {
|
|
|
|
found := false
|
|
|
|
|
|
|
|
for _, e2 := range a2 {
|
|
|
|
if e1 == e2 {
|
|
|
|
found = true
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if !found {
|
|
|
|
a = append(a, e1)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return a
|
|
|
|
}
|
|
|
|
|
2019-07-21 22:22:30 +02:00
|
|
|
// StringMapSubtract subtracts the content of structmap m2 from structmap m1
|
2019-07-21 19:58:19 +02:00
|
|
|
func StringMapSubtract(m1, m2 map[string]string) map[string]string {
|
2015-07-14 22:51:12 +02:00
|
|
|
m := map[string]string{}
|
|
|
|
|
|
|
|
for k1, v1 := range m1 {
|
|
|
|
if v2, ok := m2[k1]; ok {
|
|
|
|
if v2 != v1 {
|
|
|
|
m[k1] = v1
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
m[k1] = v1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return m
|
|
|
|
}
|
|
|
|
|
2019-07-21 22:22:30 +02:00
|
|
|
// StructMapSubtract subtracts the content of structmap m2 from structmap m1
|
2019-07-21 19:58:19 +02:00
|
|
|
func StructMapSubtract(m1, m2 map[string]struct{}) map[string]struct{} {
|
2015-07-14 22:51:12 +02:00
|
|
|
m := map[string]struct{}{}
|
|
|
|
|
|
|
|
for k1, v1 := range m1 {
|
|
|
|
if _, ok := m2[k1]; !ok {
|
|
|
|
m[k1] = v1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return m
|
|
|
|
}
|