-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.go
45 lines (35 loc) · 920 Bytes
/
main.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 main
import (
"net"
"os"
"os/signal"
"syscall"
v2 "github.com/envoyproxy/go-control-plane/envoy/service/accesslog/v2"
"go.uber.org/zap"
"google.golang.org/grpc"
"github.com/krish512/ambassador_logservice_es/pkg/elastic"
l "github.com/krish512/ambassador_logservice_es/pkg/logger"
"github.com/krish512/ambassador_logservice_es/pkg/sink"
)
func main() {
// Initialize resources
logger := l.InitLogger()
elastic.InitElasticsearch()
grpcServer := grpc.NewServer()
v2.RegisterAccessLogServiceServer(grpcServer, sink.New())
l, err := net.Listen("tcp", "0.0.0.0:9001")
if err != nil {
logger.Error("Failed to open port", zap.Error(err))
}
// Handling SIGTERM
c := make(chan os.Signal)
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
go func() {
<-c
grpcServer.GracefulStop()
os.Exit(1)
}()
// Start server
logger.Info("Listening on tcp://0.0.0.0:9001")
grpcServer.Serve(l)
}