forked from gopasspw/gopass
/
helpers.go
41 lines (36 loc) · 913 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
package jsonapi
import (
"regexp"
"strings"
"golang.org/x/net/publicsuffix"
)
// isPublicSuffix returns true if this host is one users can or could directly
// register names
func isPublicSuffix(host string) bool {
suffix, _ := publicsuffix.PublicSuffix(host)
return host == suffix
}
func regexSafeLower(str string) string {
return regexp.QuoteMeta(strings.ToLower(str))
}
func convertMixedMapInterfaces(i interface{}) interface{} {
switch x := i.(type) {
case map[string]interface{}:
stringMap := map[string]interface{}{}
for k, v := range x {
stringMap[k] = convertMixedMapInterfaces(v)
}
return stringMap
case map[interface{}]interface{}:
stringMap := map[string]interface{}{}
for k, v := range x {
stringMap[k.(string)] = convertMixedMapInterfaces(v)
}
return stringMap
case []interface{}:
for i, v := range x {
x[i] = convertMixedMapInterfaces(v)
}
}
return i
}