-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
68 lines (60 loc) · 1.62 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
package main
import (
"flag"
"fmt"
"net"
"os"
log "github.com/sirupsen/logrus"
"github.com/SailGame/Core/data/memory"
cpb "github.com/SailGame/Core/pb/core"
"github.com/SailGame/Core/server"
"google.golang.org/grpc"
"google.golang.org/grpc/reflection"
)
var (
serverAddr = flag.String("serverAddr", "0.0.0.0:8080", "The server address in the format of host:port")
logFile = flag.String("logFile", "", "The log file of GoDock")
logLevel = flag.String("logLevel", "Info", "The log level. (Debug/Info/Warn/Error)")
)
func initLog() {
log.SetFormatter(&log.JSONFormatter{})
if *logFile == "" {
log.SetOutput(os.Stdout)
} else {
f, err := os.OpenFile(*logFile, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
if err != nil {
panic(fmt.Sprintf("error opening logFile(%s): %v", *logFile, err))
}
log.SetOutput(f)
}
if *logLevel == "Debug" {
log.SetLevel(log.DebugLevel)
} else if *logLevel == "Info" {
log.SetLevel(log.InfoLevel)
} else if *logLevel == "Warn" {
log.SetLevel(log.WarnLevel)
} else if *logLevel == "Error" {
log.SetLevel(log.ErrorLevel)
} else {
panic(fmt.Sprintf("Unknown logLevel: %s", *logLevel))
}
}
func main() {
flag.Parse()
initLog()
lis, err := net.Listen("tcp", *serverAddr)
if err != nil {
log.Fatalf("failed to listen: %v", err)
}
s := grpc.NewServer()
coreServer, err := server.NewCoreServer(&server.CoreServerConfig{
MStorage: memory.NewStorage(),
})
if err != nil {
log.Fatalf("failed to create core server: %v", err)
}
cpb.RegisterGameCoreServer(s, coreServer)
reflection.Register(s)
log.Infof("Start Game Core Server at %s", *serverAddr)
log.Fatal(s.Serve(lis))
}