forked from Velocidex/velociraptor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathslice.go
42 lines (35 loc) · 779 Bytes
/
slice.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
package utils
import (
"reflect"
"github.com/Velocidex/ordereddict"
)
func DictGetStringSlice(a *ordereddict.Dict, field string) []string {
value, ok := a.Get(field)
if ok {
return ConvertToStringSlice(value)
}
return nil
}
func ConvertToStringSlice(a interface{}) []string {
result := []string{}
a_value := reflect.Indirect(reflect.ValueOf(a))
a_type := a_value.Type()
if a_type.Kind() == reflect.Slice {
for i := 0; i < a_value.Len(); i++ {
element := a_value.Index(i).Interface()
element_str, ok := element.(string)
if ok {
result = append(result, element_str)
}
}
}
return result
}
func DeduplicateStringSlice(in []string) (out []string) {
for _, i := range in {
if !InString(out, i) {
out = append(out, i)
}
}
return out
}