package main
import (
"embed"
"io/fs"
"log"
"net/http"
"time"
"theskyscape.com/repo/skydeck/controllers"
"theskyscape.com/repo/skydeck/models"
"theskyscape.com/repo/skykit"
)
//go:embed all:views
var views embed.FS
func main() {
// Sync database on startup
models.DB.Sync()
// Serve public files from views/public
if _, err := fs.Sub(views, "views/public"); err == nil {
public, _ := fs.Sub(views, "views")
http.Handle("GET /public/", http.FileServerFS(public))
log.Println("Serving public files at /public/")
}
// Start cleanup goroutine for stale sessions
go func() {
for {
time.Sleep(5 * time.Minute)
models.CleanupStaleSessions()
}
}()
skykit.Serve(views,
skykit.WithController(controllers.Decks()),
skykit.WithController(controllers.Gallery()),
)
}