forked from freeconf/restconf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
node.go
47 lines (45 loc) · 1.1 KB
/
node.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
47
package restconf
import (
"github.com/freeconf/restconf/stock"
"github.com/freeconf/yang/fc"
"github.com/freeconf/yang/node"
"github.com/freeconf/yang/nodeutil"
"github.com/freeconf/yang/source"
"github.com/freeconf/yang/val"
)
func Node(mgmt *Server, ypath source.Opener) node.Node {
return &nodeutil.Extend{
Base: nodeutil.ReflectChild(mgmt),
OnChild: func(p node.Node, r node.ChildRequest) (node.Node, error) {
switch r.Meta.Ident() {
case "web":
if r.New {
mgmt.Web = stock.NewHttpServer(mgmt)
}
if mgmt.Web != nil {
return stock.WebServerNode(mgmt.Web), nil
}
default:
return p.Child(r)
}
return nil, nil
},
OnField: func(p node.Node, r node.FieldRequest, hnd *node.ValueHandle) error {
switch r.Meta.Ident() {
case "debug":
if r.Write {
fc.DebugLog(hnd.Val.Value().(bool))
} else {
hnd.Val = val.Bool(fc.DebugLogEnabled())
}
case "streamCount":
hnd.Val = val.Int32(mgmt.notifiers.Len())
case "subscriptionCount":
hnd.Val = val.Int32(subscribeCount)
default:
return p.Field(r, hnd)
}
return nil
},
}
}