-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
51 lines (44 loc) · 992 Bytes
/
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
package main
import (
"log"
"os"
"os/signal"
"syscall"
"github.com/OpenFarLands/TheStoneProxy/src/api"
"github.com/OpenFarLands/TheStoneProxy/src/api/metrics"
"github.com/OpenFarLands/TheStoneProxy/src/config"
"github.com/OpenFarLands/TheStoneProxy/src/server"
)
func main() {
conf, err := config.New("./config.toml")
if err != nil {
log.Panic(err)
}
serv, err := server.New(conf.Network.LocalAddress, conf.Network.RemoteAddress, conf)
if err != nil {
log.Panic(err)
}
go serv.StartHandle()
go func() {
if conf.Api.UseApiServer {
err = api.Setup(conf, &serv.Clients)
if err != nil {
log.Panicf("Api server error: %v", err)
}
}
if conf.Metrics.UsePrometheus {
err = metrics.Setup(conf)
if err != nil {
log.Panicf("Prometheus server error: %v", err)
}
}
}()
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
func() {
<-c
log.Print("Stopping the server...")
serv.StopHandle()
os.Exit(1)
}()
}