-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
61 lines (47 loc) · 1.46 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
package main
import (
"flag"
"fmt"
"math/rand"
"net"
"os"
"time"
"github.com/YarikRevich/go-demonizer/pkg/demonizer"
externalapiimp "github.com/YarikRevich/hide-seek-server/internal/api/external-api/v1/implementation"
externalapiproto "github.com/YarikRevich/hide-seek-server/internal/api/external-api/v1/proto"
"github.com/YarikRevich/hide-seek-server/internal/cache"
"github.com/YarikRevich/hide-seek-server/internal/interceptors"
"github.com/YarikRevich/hide-seek-server/internal/monitoring"
"github.com/YarikRevich/hide-seek-server/tools/params"
"github.com/YarikRevich/hide-seek-server/tools/printer"
"github.com/sirupsen/logrus"
"google.golang.org/grpc"
"google.golang.org/grpc/encoding/gzip"
)
func init() {
rand.Seed(time.Now().Unix())
flag.Parse()
if params.IsDemon() {
demonizer.DemonizeThisProcess()
}
logrus.SetFormatter(logrus.StandardLogger().Formatter)
logrus.SetOutput(os.Stderr)
logrus.SetLevel(logrus.InfoLevel)
printer.PrintWelcomeMessage()
}
func main() {
conn, err := net.Listen("tcp", fmt.Sprintf("%s:%s", params.GetServerIP(), params.GetServerPort()))
if err != nil {
logrus.Fatal(err)
}
monitoring.UseMonitoring().ListenAndServe()
opts := []grpc.ServerOption{
grpc.ChainUnaryInterceptor(
interceptors.NewInterceptorManager(),
)}
s := grpc.NewServer(opts...)
grpc.UseCompressor(gzip.Name)
cache.UseCache()
externalapiproto.RegisterExternalServiceServer(s, externalapiimp.NewExternalService())
s.Serve(conn)
}