-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
54 lines (47 loc) · 1.12 KB
/
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
46
47
48
49
50
51
52
53
54
package main
import (
"github.com/leaq-ru/classifier/classifier"
"github.com/leaq-ru/classifier/classifierimpl"
"github.com/leaq-ru/classifier/config"
"github.com/leaq-ru/classifier/logger"
graceful "github.com/leaq-ru/lib-graceful"
pbClassifier "github.com/leaq-ru/proto/codegen/go/classifier"
"google.golang.org/grpc"
"google.golang.org/grpc/health"
"google.golang.org/grpc/health/grpc_health_v1"
"log"
"net"
"strings"
"sync"
)
func main() {
cfg, err := config.NewConfig()
if err != nil {
log.Fatal(err)
}
logg, err := logger.NewLogger(cfg.LogLevel)
if err != nil {
log.Fatal(err)
}
cls, err := classifier.NewClassifier()
logg.Must(err)
srv := grpc.NewServer()
grpc_health_v1.RegisterHealthServer(srv, health.NewServer())
pbClassifier.RegisterClassifierServer(srv, classifierimpl.NewServer(logg.ZL, cls))
lis, err := net.Listen("tcp", strings.Join([]string{
"0.0.0.0",
cfg.Grpc.Port,
}, ":"))
logg.Must(err)
var wg sync.WaitGroup
wg.Add(2)
go func() {
defer wg.Done()
graceful.HandleSignals(srv.GracefulStop)
}()
go func() {
defer wg.Done()
logg.Must(srv.Serve(lis))
}()
wg.Wait()
}