-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.go
61 lines (50 loc) · 1.16 KB
/
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
51
52
53
54
55
56
57
58
59
60
61
package scarf
import (
"github.com/go-nacelle/nacelle"
"github.com/go-nacelle/grpcbase"
"google.golang.org/grpc"
)
type (
serverShim struct {
Services nacelle.ServiceContainer `service:"container"`
endpointSet EndpointSet
server *grpcbase.Server
}
)
func NewServer(endpointSet EndpointSet) nacelle.Process {
return &serverShim{
endpointSet: endpointSet,
}
}
func (s *serverShim) Init(config nacelle.Config) error {
middleware := s.endpointSet.Middleware()
for _, m := range middleware {
if err := s.Services.Inject(m); err != nil {
return err
}
}
for _, m := range middleware {
if err := m.Init(); err != nil {
return err
}
}
s.server = grpcbase.NewServer(
s.endpointSet,
grpcbase.WithServerOptions(
grpc.UnaryInterceptor(makeUnaryInterceptor(middleware)),
grpc.StreamInterceptor(makeStreamInterceptor(middleware)),
grpc.StatsHandler(NewStatsHandler(nil)), // TODO - configure
),
)
if err := s.Services.Inject(s.server); err != nil {
return err
}
err := s.server.Init(config)
return err
}
func (s *serverShim) Start() error {
return s.server.Start()
}
func (s *serverShim) Stop() error {
return s.server.Stop()
}