MCPcopy Index your code
hub / github.com/koding/kite / collect

Method collect

dnode/scrub.go:30–68  ·  view source on GitHub ↗
(rv reflect.Value, path Path, callbacks map[string]Path)

Source from the content-addressed store, hash-verified

28var dnodeFunctionType = reflect.TypeOf(new(Function)).Elem()
29
30func (s *Scrubber) collect(rv reflect.Value, path Path, callbacks map[string]Path) {
31 switch rv.Kind() {
32 case reflect.Interface:
33 if !rv.IsNil() {
34 s.collect(rv.Elem(), path, callbacks)
35 }
36 case reflect.Ptr:
37 if rv.IsNil() {
38 return
39 }
40 // collect from structs that define pointer reciver methods.
41 if elem := rv.Elem(); elem.Kind() == reflect.Struct {
42 s.fields(elem, path, callbacks)
43 s.methods(rv, path, callbacks)
44 } else {
45 s.collect(elem, path, callbacks)
46 }
47 case reflect.Array, reflect.Slice:
48 for i, v := 0, rv.Len(); i < v; i++ {
49 s.collect(rv.Index(i), append(path, i), callbacks)
50 }
51 case reflect.Map:
52 for _, mrv := range rv.MapKeys() {
53 s.collect(rv.MapIndex(mrv), append(path, mrv.String()), callbacks)
54 }
55 case reflect.Struct:
56 // register callback functions wrapper.
57 if rv.Type() == dnodeFunctionType {
58 if cb := rv.Interface().(Function); cb.Caller != nil {
59 s.register(cb.Caller.(callback), path, callbacks)
60 }
61 return
62 }
63 s.fields(rv, path, callbacks)
64 s.methods(rv, path, callbacks)
65 case reflect.Func:
66 panic("cannot marshal func, use Callback() to wrap it")
67 }
68}
69
70// fields walks over a structure and scrubs its fields.
71func (s *Scrubber) fields(rv reflect.Value, path Path, callbacks map[string]Path) {

Callers 2

ScrubMethod · 0.95
fieldsMethod · 0.95

Calls 4

fieldsMethod · 0.95
methodsMethod · 0.95
registerMethod · 0.95
StringMethod · 0.45

Tested by

no test coverage detected