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 {
|
2019-04-04 11:18:19 +00:00
|
|
|
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() {
|
2019-04-06 18:36:57 +00:00
|
|
|
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)
|
2019-04-06 18:36:57 +00:00
|
|
|
log.Fatal(http.ListenAndServe(addr, app.router))
|
2019-04-02 14:28:06 +00:00
|
|
|
}
|