aboutsummaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2022-12-01 23:05:59 +0100
committerAlex Auvolat <alex@adnab.me>2022-12-01 23:25:26 +0100
commit5eed8fa506bbd24469ec4d42a183928be89a325b (patch)
tree3ed0e5f514ec1c628bd6c0bbe634d12f5cb8ada4 /main.go
parent3c846b6a59c1e725b56b7784c30cfbd5a3dc080b (diff)
downloadguichet-5eed8fa506bbd24469ec4d42a183928be89a325b.tar.gz
guichet-5eed8fa506bbd24469ec4d42a183928be89a325b.zip
Make repo into a Nix flake
Diffstat (limited to 'main.go')
-rw-r--r--main.go13
1 files changed, 10 insertions, 3 deletions
diff --git a/main.go b/main.go
index d574f3f..137b81c 100644
--- a/main.go
+++ b/main.go
@@ -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{})