nirvash/nirvash.go

46 lines
1 KiB
Go
Raw Normal View History

package main
import (
"os"
"path/filepath"
"net/http"
"nilfm.cc/git/quartzgun/indentalUserDB"
"nilfm.cc/git/quartzgun/router"
"nilfm.cc/git/quartzgun/renderer"
"nilfm.cc/git/quartzgun/middleware"
"nilfm.cc/git/nirvash/cmd"
"nilfm.cc/git/nirvash/config"
)
func main() {
cfg := config.Read()
udb := indentalUserDB.CreateIndentalUserDB(
filepath.Join(
config.GetConfigLocation(),
"user.db"))
if cmd.Process(os.Args, udb, cfg) {
os.Exit(0)
}
if config.IsNull(cfg) {
config.RunWizard(cfg)
}
rtr := &router.Router{
StaticPaths: map[string]string{
"/static": cfg.AssetRoot,
},
}
rtr.Get("/login", renderer.Template(
"templates/login.html"))
rtr.Post("/login", middleware.Authorize("/", udb, "/login?tryagain=1"))
rtr.Get("/", middleware.Protected(
renderer.Template(
"templates/cms_list.html",
"templates/header.html",
"templates/footer.html"), http.MethodGet, udb, "/login"))
http.ListenAndServe(":8080", rtr)
}