diff options
author | Alex Auvolat <alex@adnab.me> | 2022-12-01 23:05:59 +0100 |
---|---|---|
committer | Alex Auvolat <alex@adnab.me> | 2022-12-01 23:25:26 +0100 |
commit | 5eed8fa506bbd24469ec4d42a183928be89a325b (patch) | |
tree | 3ed0e5f514ec1c628bd6c0bbe634d12f5cb8ada4 /main.go | |
parent | 3c846b6a59c1e725b56b7784c30cfbd5a3dc080b (diff) | |
download | guichet-5eed8fa506bbd24469ec4d42a183928be89a325b.tar.gz guichet-5eed8fa506bbd24469ec4d42a183928be89a325b.zip |
Make repo into a Nix flake
Diffstat (limited to 'main.go')
-rw-r--r-- | main.go | 13 |
1 files changed, 10 insertions, 3 deletions
@@ -57,6 +57,9 @@ var config *ConfigFile const SESSION_NAME = "guichet_session" +var staticPath = "./static" +var templatePath = "./templates" + var store sessions.Store = nil func readConfig() ConfigFile { @@ -94,6 +97,10 @@ func readConfig() ConfigFile { return config_file } +func getTemplate(name string) *template.Template { + return template.Must(template.ParseFiles(templatePath+"/layout.html", templatePath+"/"+name)) +} + func main() { flag.Parse() @@ -127,7 +134,7 @@ func main() { r.HandleFunc("/admin/ldap/{dn}", handleAdminLDAP) r.HandleFunc("/admin/create/{template}/{super_dn}", handleAdminCreate) - staticfiles := http.FileServer(http.Dir("static")) + staticfiles := http.FileServer(http.Dir(staticPath)) r.Handle("/static/{file:.*}", http.StripPrefix("/static/", staticfiles)) log.Printf("Starting HTTP server on %s", config.HttpBindAddr) @@ -296,7 +303,7 @@ type HomePageData struct { } func handleHome(w http.ResponseWriter, r *http.Request) { - templateHome := template.Must(template.ParseFiles("templates/layout.html", "templates/home.html")) + templateHome := getTemplate("home.html") login := checkLogin(w, r) if login == nil { @@ -338,7 +345,7 @@ type LoginFormData struct { } func handleLogin(w http.ResponseWriter, r *http.Request) *LoginInfo { - templateLogin := template.Must(template.ParseFiles("templates/layout.html", "templates/login.html")) + templateLogin := getTemplate("login.html") if r.Method == "GET" { templateLogin.Execute(w, LoginFormData{}) |