/
functions.go
49 lines (41 loc) · 1.08 KB
/
functions.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
package utils
import (
"strings"
)
// Search returns first index where found, otherwise -1
func Search(list []string, a string) int {
for i, elem := range list {
if elem == a {
return i
}
}
return -1
}
// RemoveIndex removes item from slice at index
func RemoveIndex(list []string, index int) []string {
list[index] = list[len(list)-1]
list[len(list)-1] = ""
list = list[:len(list)-1]
return list
}
// MergeMaps merges multiple maps into one; duplicate k-v in subsequent maps will override previous ones
func MergeMaps(maps ...map[string]string) map[string]string {
mergedMap := make(map[string]string)
for _, innerMap := range maps {
for k, v := range innerMap {
mergedMap[k] = v
}
}
return mergedMap
}
// CleanupTables filters out 'bigbucket' and '/' from tables []string
func CleanupTables(tables []string) []string {
cleanTables := []string{}
for _, table := range tables {
cleanTable := strings.Replace(strings.Replace(table, "bigbucket", "", 1), "/", "", -1)
if cleanTable != "" {
cleanTables = append(cleanTables, cleanTable)
}
}
return cleanTables
}