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

62 lines
1020 B
Go
Raw Permalink Normal View History

2019-04-02 14:28:06 +00:00
package main
import (
"fmt"
"log"
"net/http"
2019-05-26 20:32:02 +00:00
"os"
"os/signal"
"syscall"
2019-10-13 11:13:11 +00:00
"github.com/gobuffalo/packr/v2"
"github.com/gorilla/mux"
2019-04-02 14:28:06 +00:00
)
type kis3 struct {
router *mux.Router
staticBox *packr.Box
2020-04-22 19:40:28 +00:00
telegram *telegram
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
)
2019-10-13 11:13:11 +00:00
func main() {
// 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)
}
2020-04-22 19:40:28 +00:00
initTelegram()
2019-05-26 20:32:02 +00:00
initRouter()
2019-10-13 11:13:11 +00:00
// Start
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()
2020-04-22 19:40:28 +00:00
if app.telegram != nil {
initTelegramRouter()
2019-05-27 13:03:30 +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
}