From 9038110f09c1bf708a2db101093e28c8075f3d6b Mon Sep 17 00:00:00 2001 From: Stephen McQuay Date: Mon, 7 Jan 2013 23:02:08 -0800 Subject: [PATCH] preparing sj.mcquay.me flags for launchd --- main.go | 14 ++++++++++++-- index.html => templates/index.html | 0 2 files changed, 12 insertions(+), 2 deletions(-) rename index.html => templates/index.html (100%) diff --git a/main.go b/main.go index 4509470..5e1e6a2 100644 --- a/main.go +++ b/main.go @@ -6,6 +6,7 @@ import ( "io/ioutil" "log" "net/http" + "path/filepath" "sync" "text/template" ) @@ -22,10 +23,11 @@ var m = sync.Mutex{} var addr = flag.String("addr", ":8000", "http service address") var static_files = flag.String("static", "./static", "location of static files") var db_file = flag.String("db", "db.json", "output database") -var homeTempl = template.Must(template.ParseFiles("index.html")) +var template_dir = flag.String("templates", "templates", "template dir") +var templates *template.Template func homeHandler(c http.ResponseWriter, req *http.Request) { - homeTempl.Execute(c, req.Host) + templates.Execute(c, req.Host) } func passHandler(resp http.ResponseWriter, req *http.Request) { @@ -69,6 +71,14 @@ func init_db() { func main() { flag.Parse() init_db() + pattern := filepath.Join(*template_dir, "*.html") + var err error + templates, err = template.ParseGlob(pattern) + if err != nil { + println(*template_dir) + println(pattern) + log.Fatal("problem parsing template dir:", *template_dir) + } http.HandleFunc("/", homeHandler) http.HandleFunc("/pass", passHandler) http.HandleFunc("/api/1.0/creds/", credHandler) diff --git a/index.html b/templates/index.html similarity index 100% rename from index.html rename to templates/index.html