-
Notifications
You must be signed in to change notification settings - Fork 25
/
provide.go
37 lines (31 loc) · 1.05 KB
/
provide.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
package rpc
import (
"go.uber.org/fx"
"google.golang.org/grpc"
"google.golang.org/grpc/health"
"google.golang.org/grpc/health/grpc_health_v1"
rpcv1 "github.com/fluxninja/aperture/v2/api/gen/proto/go/aperture/rpc/v1"
"github.com/fluxninja/aperture/v2/pkg/log"
)
// ServerModule are components needed for server-side of rpc.
var ServerModule = fx.Options(
fx.Provide(NewClients),
fx.Provide(NewStreamServer),
fx.Invoke(RegisterStreamServer),
)
// ClientModule are components needed for client-side of rpc
//
// Note: Not providing StreamClient, as this package is generic and does not
// know what to connect to.
var ClientModule = fx.Provide(NewHandlerRegistry)
// RegisterStreamServer registers the handler on grpc.Server
//
// To be used in fx.Invoke.
func RegisterStreamServer(handler *StreamServer, server *grpc.Server, healthsrv *health.Server) {
rpcv1.RegisterCoordinatorServer(server, handler)
healthsrv.SetServingStatus(
"aperture.rpc.v1.Coordinator",
grpc_health_v1.HealthCheckResponse_SERVING,
)
log.Info().Msg("Coordinator handler registered")
}