-
Notifications
You must be signed in to change notification settings - Fork 0
/
grpc.go
30 lines (24 loc) · 796 Bytes
/
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
package server
import (
"context"
"net"
grpc_middleware "github.com/grpc-ecosystem/go-grpc-middleware"
grpc_recovery "github.com/grpc-ecosystem/go-grpc-middleware/recovery"
grpc_prometheus "github.com/grpc-ecosystem/go-grpc-prometheus"
"google.golang.org/grpc"
"google.golang.org/grpc/reflection"
)
// serve grpc request
func (s *Server) grpcServe(ctx context.Context, l net.Listener) error {
opts := grpc.UnaryInterceptor(grpc_middleware.ChainUnaryServer(
grpc_prometheus.UnaryServerInterceptor,
grpc_recovery.UnaryServerInterceptor(),
))
server := grpc.NewServer(opts)
s.register.grpc(server) // register handler
reflection.Register(server)
grpc_prometheus.Register(server)
grpc_prometheus.EnableHandlingTimeHistogram()
s.server.grpc = server
return server.Serve(l)
}