-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
70 lines (60 loc) · 1.75 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package main
import (
"context"
"flag"
"os"
"os/signal"
"syscall"
"github.com/bradfitz/gomemcache/memcache"
"github.com/ninja-dark/fibonacci_testtask/config"
"github.com/ninja-dark/fibonacci_testtask/internal/fiboLogic"
grpcsrv "github.com/ninja-dark/fibonacci_testtask/internal/infrastructure/grpcSrv"
"github.com/ninja-dark/fibonacci_testtask/internal/infrastructure/rest/api/handler"
"github.com/ninja-dark/fibonacci_testtask/internal/infrastructure/rest/server"
"github.com/sirupsen/logrus"
"google.golang.org/grpc"
)
const(
configPath = "config/configs.yaml"
)
func main() {
//set logrus
logrus.SetFormatter(new(logrus.JSONFormatter))
path := flag.String("config", configPath, "file path")
flag.Parse()
//parse config
cfg, err := config.ParseConfig(*path)
if err != nil {
logrus.Fatalf("error initializating configs: %s" , err.Error())
}
restApi := cfg.Rest
grpcPort := cfg.GrpcPort
cache := cfg.Memcache
m := memcache.New(cache)
if err := m.Ping(); err != nil {
logrus.Error("Cannot to connect to memcache srv")
}
f:= fibologic.Fibo{Cache: m}
//srart rest api
srv := new(server.Server)
rest := handler.Handler{
Services: &f,
}
go func() {
if err := srv.Run(restApi, rest.InitRouters()); err != nil{
logrus.Fatal("error occured while running rest api server: %s", err.Error())
}
}()
logrus.Print("Fibonacci Started")
// start grps
grpcNew:= grpc.NewServer()
grpcSrv:= &grpcsrv.ServerG{Handler: &f}
go grpcsrv.Run(grpcNew, grpcSrv, grpcPort)
quit := make(chan os.Signal, 1)
signal.Notify(quit, syscall.SIGTERM, syscall.SIGINT)
<- quit
logrus.Print("Fibonacci Shitting Down")
if err := srv.Shutdown(context.Background()); err != nil {
logrus.Errorf("error occured on server shutting down: %s", err.Error())
}
}