-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.go
50 lines (42 loc) · 946 Bytes
/
server.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
48
49
50
package netconf
import (
"github.com/freeconf/restconf/device"
"github.com/freeconf/restconf/estream"
"github.com/freeconf/yang/fc"
)
type Server struct {
Ver string
main device.Device
sessNum int64
sshHandler *SshHandler
streams *estream.Service
}
type SessionManager interface {
NextSessionId() int64
StreamService() *estream.Service
HandleErr(err error)
}
func NewServer(d *device.Local, streams *estream.Service) *Server {
s := &Server{
main: d,
streams: streams,
}
s.sshHandler = NewSshHandler(s, d)
if err := d.Add("fc-netconf", Api(s)); err != nil {
panic(err)
}
if err := d.Add("ietf-subscribed-notifications", estream.Manage(streams)); err != nil {
panic(err)
}
return s
}
func (s *Server) StreamService() *estream.Service {
return s.streams
}
func (s *Server) HandleErr(err error) {
fc.Err.Print(err)
}
func (s *Server) NextSessionId() int64 {
s.sessNum++
return s.sessNum
}