Konfi-Castle-Kasino/main.go

87 lines
2.5 KiB
Go
Raw Permalink Normal View History

2017-06-15 09:30:32 +00:00
package main
import (
2019-09-02 20:19:49 +00:00
"context"
2017-08-30 20:23:35 +00:00
"fmt"
2019-09-01 20:59:51 +00:00
"git.kolaente.de/konrad/Konfi-Castle-Kasino/pkg/config"
"git.kolaente.de/konrad/Konfi-Castle-Kasino/pkg/models"
"git.kolaente.de/konrad/Konfi-Castle-Kasino/pkg/router"
2019-09-04 20:11:13 +00:00
"git.kolaente.de/konrad/Konfi-Castle-Kasino/pkg/windows"
2019-09-02 20:19:49 +00:00
"github.com/labstack/gommon/log"
"os"
"os/signal"
"time"
2017-06-15 09:30:32 +00:00
)
func main() {
2017-06-17 16:49:01 +00:00
//Startup Banner
2019-09-01 17:02:25 +00:00
fmt.Println(`
################################################################
# _ __ __ _ _____ _ _ #
# | | / / / _(_) ____ / __ \ | | | | #
# | |/ / ___ _ __ | |_ _ / __ \| / \/ __ _ ___| |_| | ___ #
# | \ / _ \| '_ \| _| |/ / _` + "`" + ` | | / _` + "`" + ` / __| __| |/ _ \ #
# | |\ \ (_) | | | | | | | | (_| | \__/\ (_| \__ \ |_| | __/ #
# \_| \_/\___/|_| |_|_| |_|\ \__,_|\____/\__,_|___/\__|_|\___| #
# \____/ #
# #
# _ __ _ #
# | | / / (_) #
# | |/ / __ _ ___ _ _ __ ___ #
# | \ / _` + "`" + ` / __| | '_ \ / _ \ #
# | |\ \ (_| \__ \ | | | | (_) | #
# \_| \_/\__,_|___/_|_| |_|\___/ #
# #
# © 2017-2019 Konrad Langenberg (konradlangenberg.de) #
2019-09-08 11:30:24 +00:00
# Version: ` + models.Version + ` #
2019-09-01 17:02:25 +00:00
################################################################`)
2017-06-17 16:49:01 +00:00
2019-09-02 20:33:11 +00:00
// Config
2019-09-01 20:59:51 +00:00
config.InitConfig()
2019-09-02 20:33:11 +00:00
// DB init - Create tables
models.DBinit()
// Echo init
2019-09-01 20:59:51 +00:00
e := router.NewEcho()
router.RegisterRoutes(e)
2019-09-02 20:19:49 +00:00
2019-09-01 20:59:51 +00:00
// Start server
go func() {
if err := e.Start(config.GetInterface()); err != nil {
e.Logger.Info("shutting down...")
}
}()
2017-08-31 16:56:49 +00:00
2019-09-14 17:15:41 +00:00
if config.GetSaveMetrics() {
log.Info("Saving Metrics.")
go func() {
for {
models.AddMetric()
time.Sleep(60 * time.Second)
}
}()
}
2019-09-04 20:11:13 +00:00
// Windows
if config.GetOpenWindows() {
go windows.OpenWindows()
}
2019-09-04 20:59:33 +00:00
if config.GetOpenBrowser() {
go windows.OpenNativeWindows()
}
2019-09-02 20:19:49 +00:00
// Wait for interrupt signal to gracefully shutdown the server with
// a timeout of 10 seconds.
quit := make(chan os.Signal, 1)
signal.Notify(quit, os.Interrupt)
<-quit
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
log.Infof("Shutting down...")
if err := e.Shutdown(ctx); err != nil {
e.Logger.Fatal(err)
}
2017-06-15 09:30:32 +00:00
}