jlelse
/
kis3
Archived
1
Fork 0
This repository has been archived on 2021-01-04. You can view files and clone it, but cannot push or open issues or pull requests.
kis3/main.go

57 lines
928 B
Go
Raw Normal View History

2019-04-02 14:28:06 +00:00
package main
import (
"fmt"
"github.com/gobuffalo/packr/v2"
"github.com/gorilla/mux"
"log"
"net/http"
2019-05-26 20:32:02 +00:00
"os"
"os/signal"
"syscall"
2019-04-02 14:28:06 +00:00
)
type kis3 struct {
router *mux.Router
staticBox *packr.Box
2019-04-02 14:28:06 +00:00
}
var (
2019-05-01 09:46:52 +00:00
app = &kis3{
staticBox: packr.New("staticFiles", "./static"),
}
2019-04-02 14:28:06 +00:00
)
func init() {
2019-05-26 20:32:02 +00:00
initConfig()
e := initDatabase()
2019-04-02 14:28:06 +00:00
if e != nil {
log.Fatal("Database setup failed:", e)
}
2019-05-26 20:32:02 +00:00
initRouter()
2019-04-02 14:28:06 +00:00
}
func main() {
2019-05-26 20:32:02 +00:00
go startListeningToWeb()
go startReports()
// Graceful stop
var gracefulStop = make(chan os.Signal, 1)
signal.Notify(gracefulStop, os.Interrupt, syscall.SIGTERM)
sig := <-gracefulStop
fmt.Printf("Received signal: %+v", sig)
os.Exit(0)
2019-04-02 14:28:06 +00:00
}
2019-05-26 20:32:02 +00:00
func initRouter() {
app.router = mux.NewRouter()
2019-05-26 20:32:02 +00:00
initStatsRouter()
initTrackingRouter()
2019-04-02 14:28:06 +00:00
}
2019-05-26 20:32:02 +00:00
func startListeningToWeb() {
2019-05-01 09:46:52 +00:00
port := appConfig.Port
2019-04-02 14:28:06 +00:00
addr := ":" + port
fmt.Printf("Listening to %s\n", addr)
log.Fatal(http.ListenAndServe(addr, app.router))
2019-04-02 14:28:06 +00:00
}