-
Notifications
You must be signed in to change notification settings - Fork 23
/
provide.go
45 lines (39 loc) · 1.39 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
38
39
40
41
42
43
44
45
package preview
import (
"go.uber.org/fx"
"google.golang.org/grpc"
"google.golang.org/grpc/health"
"google.golang.org/grpc/health/grpc_health_v1"
flowpreviewv1 "github.com/fluxninja/aperture/v2/api/gen/proto/go/aperture/flowcontrol/preview/v1"
cfg "github.com/fluxninja/aperture/v2/pkg/config"
"github.com/fluxninja/aperture/v2/pkg/log"
"github.com/fluxninja/aperture/v2/pkg/net/grpcgateway"
previewconfig "github.com/fluxninja/aperture/v2/pkg/policies/flowcontrol/service/preview/config"
)
// Module provides preview handler and registers the service.
func Module() fx.Option {
return fx.Options(
fx.Provide(NewHandler),
grpcgateway.RegisterHandler{Handler: flowpreviewv1.RegisterFlowPreviewServiceHandlerFromEndpoint}.Annotate(),
fx.Invoke(Register),
)
}
// Register registers the handler on grpc.Server.
func Register(handler *Handler,
server *grpc.Server,
healthsrv *health.Server,
unmarshaller cfg.Unmarshaller,
) error {
var config previewconfig.FlowPreviewConfig
if err := unmarshaller.UnmarshalKey(previewconfig.Key, &config); err != nil {
return err
}
if !config.Enabled {
log.Info().Msg("flow preview service disabled")
return nil
}
flowpreviewv1.RegisterFlowPreviewServiceServer(server, handler)
healthsrv.SetServingStatus("aperture.flowcontrol.v1.FlowPreviewService", grpc_health_v1.HealthCheckResponse_SERVING)
log.Info().Msg("Preview handler registered")
return nil
}