162 lines
4.7 KiB
Go
162 lines
4.7 KiB
Go
package main
|
|
|
|
import (
|
|
"github.com/labstack/echo"
|
|
"github.com/labstack/echo/middleware"
|
|
"github.com/labstack/gommon/log"
|
|
"html/template"
|
|
|
|
|
|
"fmt"
|
|
"github.com/astaxie/session"
|
|
_ "github.com/astaxie/session/providers/memory"
|
|
"github.com/asticode/go-astilectron"
|
|
"github.com/asticode/go-astilog"
|
|
"github.com/pkg/errors"
|
|
)
|
|
|
|
//Initialize Session
|
|
var GlobalSessions *session.Manager
|
|
|
|
// initialize in init() function
|
|
func Init() {
|
|
GlobalSessions, _ = session.NewManager("memory", "kasinoadmin", 43200)
|
|
go GlobalSessions.GC()
|
|
}
|
|
|
|
func main() {
|
|
//Session init
|
|
Init()
|
|
|
|
//Startup Banner
|
|
fmt.Println("################################################################")
|
|
fmt.Println("# _ __ __ _ _____ _ _ #")
|
|
fmt.Println("# | | / / / _(_) ____ / __ \\ | | | | #")
|
|
fmt.Println("# | |/ / ___ _ __ | |_ _ / __ \\| / \\/ __ _ ___| |_| | ___ #")
|
|
fmt.Println("# | \\ / _ \\| '_ \\| _| |/ / _` | | / _` / __| __| |/ _ \\ #")
|
|
fmt.Println("# | |\\ \\ (_) | | | | | | | | (_| | \\__/\\ (_| \\__ \\ |_| | __/ #")
|
|
fmt.Println("# \\_| \\_/\\___/|_| |_|_| |_|\\ \\__,_|\\____/\\__,_|___/\\__|_|\\___| #")
|
|
fmt.Println("# \\____/ #")
|
|
fmt.Println("# #")
|
|
fmt.Println("# _ __ _ #")
|
|
fmt.Println("# | | / / (_) #")
|
|
fmt.Println("# | |/ / __ _ ___ _ _ __ ___ #")
|
|
fmt.Println("# | \\ / _` / __| | '_ \\ / _ \\ #")
|
|
fmt.Println("# | |\\ \\ (_| \\__ \\ | | | | (_) | #")
|
|
fmt.Println("# \\_| \\_/\\__,_|___/_|_| |_|\\___/ #")
|
|
fmt.Println("# #")
|
|
fmt.Println("# © 2017 Konrad Langenberg (kola-entertainments.de) #")
|
|
fmt.Println("# Version: " + Version + " #")
|
|
fmt.Println("################################################################")
|
|
|
|
//Echo init
|
|
e := echo.New()
|
|
e.HideBanner = true
|
|
|
|
//Logger
|
|
e.Use(middleware.LoggerWithConfig(middleware.LoggerConfig{
|
|
Format: "${time_rfc3339}: ${remote_ip} ${method} ${status} ${uri} - ${user_agent}\n",
|
|
}))
|
|
|
|
//Static ontent
|
|
e.Static("/assets", "assets")
|
|
|
|
//Routes
|
|
e.GET("/", showList)
|
|
e.GET("/list", getList)
|
|
e.GET("/admin", adminHandler)
|
|
e.GET("/logout", logout)
|
|
e.GET("/ws", ws)
|
|
|
|
e.POST("/login", login)
|
|
e.POST("/update", update)
|
|
e.POST("/delete", deleteKonfi)
|
|
e.POST("/add", addKonfi)
|
|
|
|
//Template
|
|
t := &Template{
|
|
templates: template.Must(template.ParseGlob("tpl/*.html")),
|
|
}
|
|
e.Renderer = t
|
|
|
|
//DB init - Create tables
|
|
db := DBinit()
|
|
db.Sync(&Kofi{})
|
|
db.Sync(&Gemeinde{})
|
|
|
|
//Config
|
|
SiteConf := initConfig()
|
|
|
|
//Start the server
|
|
e.Logger.SetLevel(log.ERROR)
|
|
go e.Start(SiteConf.Interface)
|
|
|
|
//Windows
|
|
// Create astilectron
|
|
var a *astilectron.Astilectron
|
|
var err error
|
|
if a, err = astilectron.New(astilectron.Options{
|
|
AppName: "Astilectron",
|
|
AppIconDefaultPath: "gopher.png",
|
|
AppIconDarwinPath: "gopher.icns",
|
|
BaseDirectoryPath: "astilectron-deps",
|
|
}); err != nil {
|
|
fmt.Println(err)
|
|
astilog.Fatal(errors.Wrap(err, "creating new astilectron failed"))
|
|
}
|
|
defer a.Close()
|
|
a.HandleSignals()
|
|
|
|
// Start
|
|
if err = a.Start(); err != nil {
|
|
fmt.Println(err)
|
|
astilog.Fatal(errors.Wrap(err, "starting failed"))
|
|
}
|
|
|
|
// Create Frontend window
|
|
var wFrontend *astilectron.Window
|
|
wFrontend, err = a.NewWindow("http://" + SiteConf.Interface, &astilectron.WindowOptions{
|
|
Center: astilectron.PtrBool(true),
|
|
Height: astilectron.PtrInt(800),
|
|
Width: astilectron.PtrInt(1200),
|
|
})
|
|
|
|
if err != nil {
|
|
fmt.Println(err)
|
|
astilog.Fatal(errors.Wrap(err, "new window failed"))
|
|
}
|
|
if err = wFrontend.Create(); err != nil {
|
|
fmt.Println(err)
|
|
astilog.Fatal(errors.Wrap(err, "creating window failed"))
|
|
}
|
|
|
|
// If several displays, move the window to the second display
|
|
var displays = a.Displays()
|
|
if len(displays) > 1 {
|
|
if displays[1].IsPrimary() {
|
|
wFrontend.MoveInDisplay(displays[0], 50, 50)
|
|
} else {
|
|
wFrontend.MoveInDisplay(displays[1], 50, 50)
|
|
}
|
|
wFrontend.Maximize()
|
|
}
|
|
|
|
// Create Admin window
|
|
var wAdmin *astilectron.Window
|
|
if wAdmin, err = a.NewWindow("http://" + SiteConf.Interface + "/admin", &astilectron.WindowOptions{
|
|
Center: astilectron.PtrBool(true),
|
|
Height: astilectron.PtrInt(700),
|
|
Width: astilectron.PtrInt(1200),
|
|
}); err != nil {
|
|
fmt.Println(err)
|
|
astilog.Fatal(errors.Wrap(err, "new window failed"))
|
|
}
|
|
if err = wAdmin.Create(); err != nil {
|
|
fmt.Println(err)
|
|
astilog.Fatal(errors.Wrap(err, "creating window failed"))
|
|
}
|
|
|
|
// Blocking pattern
|
|
a.Wait()
|
|
}
|