-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.go
36 lines (27 loc) · 956 Bytes
/
server.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
package grpc
import (
"log"
"net"
"sync"
"github.com/drhelius/grpc-demo-product/internal/impl"
"github.com/drhelius/grpc-demo-proto/product"
grpc_middleware "github.com/grpc-ecosystem/go-grpc-middleware"
grpc_opentracing "github.com/grpc-ecosystem/go-grpc-middleware/tracing/opentracing"
"github.com/opentracing/opentracing-go"
"google.golang.org/grpc"
)
func Serve(wg *sync.WaitGroup, port string) {
defer wg.Done()
lis, err := net.Listen("tcp", ":"+port)
if err != nil {
log.Fatalf("[Product] GRPC failed to listen: %v", err)
}
s := grpc.NewServer(grpc.UnaryInterceptor(grpc_middleware.ChainUnaryServer(
grpc_opentracing.UnaryServerInterceptor(grpc_opentracing.WithTracer(opentracing.GlobalTracer())),
)))
product.RegisterProductServiceServer(s, &impl.Server{})
log.Printf("[Product] Serving GRPC on localhost:%s ...", port)
if err := s.Serve(lis); err != nil {
log.Fatalf("[Product] GRPC failed to serve: %v", err)
}
}