forked from sokool/goldap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
result.go
45 lines (35 loc) · 924 Bytes
/
result.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
package ldap
import (
"gopkg.in/ldap.v2"
"github.com/sokool/goldap/sanitizer"
)
type (
Result struct {
ldap.SearchResult
filters map[string]func(*Element)
}
Element struct{ *ldap.Entry }
)
func (self *Element) Value(attribute string) string {
return self.GetAttributeValue(attribute)
}
func (self *Element) SanitizeValue(method, attribute string) string {
v, _ := sanitizer.Sanitize(method, []string{self.Value(attribute)}, []string{})
return v[0]
}
func (self *Element) Each(fn func(name string, values []string, byteValues [][]byte)) {
for _, attr := range self.Attributes {
fn(attr.Name, attr.Values, attr.ByteValues)
}
}
func (self *Result) RegisterFilter(name string, fn func(*Element)) {
self.filters[name] = fn
}
func (self *Result) Count() int {
return len(self.Entries)
}
func (self *Result) Each(fn func(int, *Element)) {
for idx, e := range self.Entries {
fn(idx, &Element{e})
}
}