-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
66 lines (58 loc) · 1.27 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
package main
import (
"github.com/bombergame/common/logs"
"github.com/bombergame/common/registry"
restful "github.com/bombergame/common/rest"
"github.com/bombergame/multiplayer-service/config"
"github.com/bombergame/multiplayer-service/services/rest"
"github.com/bombergame/multiplayer-service/utils"
"os"
"os/signal"
)
func main() {
logger := logs.NewLogger()
regClient := registry.NewClient(
registry.Config{
RegistryAddress: config.RegistryAddress,
ServiceName: config.ServiceName,
ServicePort: config.HttpPort,
ServiceHost: func() string {
host, err := os.Hostname()
if err != nil {
panic(err)
}
return host
}(),
},
)
if err := regClient.Register(); err != nil {
logger.Fatal(err)
return
}
defer func() {
if err := regClient.Deregister(); err != nil {
logger.Fatal(err)
}
}()
restSrv := rest.NewService(
rest.Config{},
rest.Components{
RoomsManager: utils.NewRoomsManager(),
Components: restful.Components{
Logger: logger,
AuthManager: utils.NewAuthManager(),
},
},
)
ch := make(chan os.Signal)
signal.Notify(ch, os.Interrupt)
go func() {
if err := restSrv.Run(); err != nil {
logger.Fatal(err)
}
}()
<-ch
if err := restSrv.Shutdown(); err != nil {
logger.Fatal(err)
}
}