-
Notifications
You must be signed in to change notification settings - Fork 1
/
grpc.go
49 lines (41 loc) · 1.11 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
package grpc
import (
"context"
"github.com/alexfalkowski/go-service/transport/grpc"
v1 "github.com/alexfalkowski/konfig/api/konfig/v1"
v1c "github.com/alexfalkowski/konfig/client/v1/config"
g "github.com/alexfalkowski/konfig/transport/grpc"
"github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
"go.opentelemetry.io/otel/metric"
"go.opentelemetry.io/otel/trace"
"go.uber.org/fx"
"go.uber.org/zap"
)
// RegisterParams for gRPC.
type RegisterParams struct {
fx.In
Lifecycle fx.Lifecycle
GRPC *grpc.Server
Mux *runtime.ServeMux
Client *v1c.Config
Logger *zap.Logger
Tracer trace.Tracer
Meter metric.Meter
Server v1.ServiceServer
}
// Register server.
func Register(params RegisterParams) error {
v1.RegisterServiceServer(params.GRPC.Server(), params.Server)
opts := g.ClientOpts{
Lifecycle: params.Lifecycle,
ClientConfig: params.Client.Config,
Logger: params.Logger,
Tracer: params.Tracer,
Meter: params.Meter,
}
conn, err := g.NewClient(opts)
if err != nil {
return err
}
return v1.RegisterServiceHandler(context.Background(), params.Mux, conn)
}