-
Notifications
You must be signed in to change notification settings - Fork 0
/
grpc.go
50 lines (42 loc) · 1.22 KB
/
grpc.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 grpc
import (
"context"
v1 "github.com/alexfalkowski/bezeichner/api/bezeichner/v1"
v1c "github.com/alexfalkowski/bezeichner/client/v1/config"
g "github.com/alexfalkowski/bezeichner/transport/grpc"
"github.com/alexfalkowski/go-service/transport/grpc"
"github.com/alexfalkowski/go-service/transport/grpc/telemetry/tracer"
"github.com/alexfalkowski/go-service/transport/http"
"go.opentelemetry.io/otel/metric"
"go.uber.org/fx"
"go.uber.org/zap"
)
// RegisterParams for gRPC.
type RegisterParams struct {
fx.In
Lifecycle fx.Lifecycle
GRPCServer *grpc.Server
HTTPServer *http.Server
ClientConfig *v1c.Config
Logger *zap.Logger
Tracer tracer.Tracer
Meter metric.Meter
Server v1.ServiceServer
}
// Register server.
func Register(params RegisterParams) error {
v1.RegisterServiceServer(params.GRPCServer.Server, params.Server)
ctx := context.Background()
opts := g.ClientOpts{
Lifecycle: params.Lifecycle,
ClientConfig: params.ClientConfig.Config,
Logger: params.Logger,
Tracer: params.Tracer,
Meter: params.Meter,
}
conn, err := g.NewClient(ctx, opts)
if err != nil {
return err
}
return v1.RegisterServiceHandler(ctx, params.HTTPServer.Mux, conn)
}