-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmanage.go
44 lines (41 loc) · 934 Bytes
/
manage.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
package gnmi
import (
"github.com/freeconf/yang/fc"
"github.com/freeconf/yang/node"
"github.com/freeconf/yang/nodeutil"
"github.com/freeconf/yang/val"
)
func Manage(s *Server) node.Node {
return &nodeutil.Basic{
OnChild: func(r node.ChildRequest) (child node.Node, err error) {
switch r.Meta.Ident() {
case "web":
return options(s), nil
}
return nil, nil
},
OnField: func(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())
}
}
return nil
},
}
}
func options(s *Server) node.Node {
opts := s.Options()
return &nodeutil.Extend{
Base: nodeutil.ReflectChild(&opts),
OnEndEdit: func(parent node.Node, r node.NodeRequest) error {
if err := parent.EndEdit(r); err != nil {
return err
}
return s.Apply(opts)
},
}
}