-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathvalue_extractor.go
41 lines (31 loc) · 947 Bytes
/
value_extractor.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 ldsview
import (
hashset "github.com/kgoins/hashset/pkg"
)
func GetValues(source *LdifParser, attrName string) ([]string, error) {
filterParts := []string{attrName}
filter := BuildAttributeFilter(filterParts)
source.SetAttributeFilter(filter)
entities, done, cont := make(chan Entity), make(chan bool), make(chan bool)
valSet := hashset.NewStrHashset()
go func(ents chan Entity, done chan bool, list *hashset.StrHashset) {
for entity := range ents {
if entity.IsEmpty() {
continue
}
attr, found := entity.GetAttribute(attrName)
if !found {
continue
}
valSet.Add(attr.Value.Values()...)
}
done <- true //signals to BuildEntities we're done processing
cont <- true //signals to self we're done processing
}(entities, done, &valSet)
err := source.BuildEntities(entities, done)
if err != nil {
return nil, err
}
<-cont // wait for dnList to be populated
return valSet.Values(), nil
}