all repos — nirvash @ b7e2dc3ab7463cc239093623befde3901dcacec7

modular CMS using the quartzgun library

nirvash.go (raw)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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)
}