-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
57 lines (46 loc) · 1.13 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
package main
import (
"fmt"
"net/http"
"os"
"os/signal"
"syscall"
"github.com/gorilla/mux"
"github.com/kainobor/slots/config"
"github.com/kainobor/slots/src/handler"
"github.com/kainobor/slots/src/logger"
"github.com/kainobor/slots/src/processor"
)
func main() {
err := logger.Init()
if err != nil {
panic("can't start logger: " + err.Error())
}
logger.Log("Logger initiated")
conf, err := config.New()
if err != nil {
logger.Err("can't read config", "error", err)
panic("Can't read config")
}
proc := processor.New(conf.Processor)
h := handler.New(conf, proc)
r := mux.NewRouter()
r.HandleFunc(conf.Handler.SpinURL, h.Spins).Methods(http.MethodPost)
logger.Log("Start to listen")
// Parallelize handling by ports
for _, port := range conf.Handler.Ports {
go func(p int) {
err = http.ListenAndServe(fmt.Sprintf(":%d", p), r)
if err != nil {
logger.Err("can't start handler", "error", err)
}
}(port)
}
// Wait until end
c := make(chan os.Signal, 1)
signal.Notify(c, syscall.SIGINT, syscall.SIGTERM, syscall.SIGHUP)
select {
case s := <-c:
logger.Log("End with signal %s", s.String())
}
}