-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
46 lines (36 loc) · 958 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
package main
import (
"context"
"fmt"
"github.com/kubikvest/api2/app"
"github.com/kubikvest/api2/games"
"net/http"
"os"
"os/signal"
"syscall"
"time"
)
func main() {
fmt.Println("Start")
user := os.Getenv("DB_USER")
pass := os.Getenv("DB_PASS")
host := os.Getenv("DB_HOST")
port := os.Getenv("DB_PORT")
db, _ := app.Open(fmt.Sprintf("%s:%s@tcp(%s:%s)/billing?charset=utf8&parseTime=True&loc=Local", user, pass, host, port))
appctx := &app.Context{DB: db}
mux := http.NewServeMux()
games.SetHandlers(mux, appctx)
s := &http.Server{
Addr: "0.0.0.0:8080",
Handler: mux,
ReadTimeout: time.Duration(1 * time.Second),
WriteTimeout: time.Duration(1 * time.Second),
}
sigchan := make(chan os.Signal)
signal.Notify(sigchan, syscall.SIGTERM, syscall.SIGINT)
go s.ListenAndServe()
<-sigchan
ctx, _ := context.WithTimeout(context.Background(), time.Duration(5*time.Second))
s.Shutdown(ctx)
fmt.Println("Stop")
}