-
Notifications
You must be signed in to change notification settings - Fork 45
/
utils.go
46 lines (40 loc) · 848 Bytes
/
utils.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
package utils
import (
"reflect"
"sort"
"unicode"
)
// Contains returns whether a string is in a string list
func Contains(needle string, haystack []string) bool {
for _, x := range haystack {
if x == needle {
return true
}
}
return false
}
// OrderedKeys takes a map and returns the ordered map keys
func OrderedKeys(mapObj interface{}) []string {
var typeNames []string
for _, k := range reflect.ValueOf(mapObj).MapKeys() {
typeNames = append(typeNames, k.String())
}
sort.Strings(typeNames)
return typeNames
}
// ToCamel camelcases the given string.
func ToCamel(in string) string {
runes := []rune(in)
var out []rune
for i, r := range runes {
if r == '_' {
continue
}
if i == 0 || runes[i-1] == '_' {
out = append(out, unicode.ToUpper(r))
continue
}
out = append(out, r)
}
return string(out)
}