forked from phillbaker/terraform-provider-elasticsearch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.go
56 lines (47 loc) · 984 Bytes
/
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
package main
import (
"fmt"
"strings"
)
func normalizeIndexTemplate(tpl map[string]interface{}) {
delete(tpl, "version")
if settings, ok := tpl["settings"]; ok {
if settingsMap, ok := settings.(map[string]interface{}); ok {
tpl["settings"] = normalizedIndexSettings(settingsMap)
}
}
}
func normalizedIndexSettings(settings map[string]interface{}) map[string]interface{} {
f := flattenMap(settings)
for k, v := range f {
f[k] = fmt.Sprintf("%v", v)
if !strings.HasPrefix(k, "index.") {
f["index."+k] = v
delete(f, k)
}
}
return f
}
func flattenMap(m map[string]interface{}) map[string]interface{} {
f := make(map[string]interface{})
for k, v := range m {
if vm, ok := v.(map[string]interface{}); ok {
fm := flattenMap(vm)
for k2, v2 := range fm {
f[k+"."+k2] = v2
}
} else {
f[k] = v
}
}
return f
}
func intp(i int) *int {
return &i
}
func stringp(s string) *string {
return &s
}
func boolp(b bool) *bool {
return &b
}