-
Notifications
You must be signed in to change notification settings - Fork 0
/
api.go
45 lines (40 loc) · 936 Bytes
/
api.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 netconf
import (
"github.com/freeconf/yang/node"
"github.com/freeconf/yang/nodeutil"
)
type api struct{}
func Api(s *Server) node.Node {
var api api
return &nodeutil.Basic{
OnChild: func(r node.ChildRequest) (child node.Node, err error) {
switch r.Meta.Ident() {
case "ssh":
return api.ssh(s.sshHandler), nil
}
return nil, nil
},
}
}
func (api api) ssh(s *SshHandler) node.Node {
return &nodeutil.Node{Object: s,
OnChild: func(n *nodeutil.Node, r node.ChildRequest) (child node.Node, err error) {
switch r.Meta.Ident() {
case "options":
return api.sshOptions(s), nil
case "status":
s := s.Status()
return n.New(r.Meta, &s)
}
return n.DoChild(r)
},
}
}
func (api api) sshOptions(s *SshHandler) node.Node {
var opts = s.Options()
return &nodeutil.Node{Object: &opts,
OnEndEdit: func(n *nodeutil.Node, r node.NodeRequest) error {
return s.Apply(opts)
},
}
}