From 3ca4994676b81f6b3382976b4b992b27d5a3b282 Mon Sep 17 00:00:00 2001 From: Stephen McQuay Date: Wed, 20 Feb 2013 21:27:09 -0800 Subject: [PATCH] Got distinct index and login pages working. --- handlers.go | 17 +++++++++++++++++ main.go | 20 +------------------- templates/index.html | 16 +++------------- 3 files changed, 21 insertions(+), 32 deletions(-) create mode 100644 handlers.go diff --git a/handlers.go b/handlers.go new file mode 100644 index 0000000..9f6aef7 --- /dev/null +++ b/handlers.go @@ -0,0 +1,17 @@ +package main + +import ( + "log" + "net/http" +) + +func homeHandler(c http.ResponseWriter, req *http.Request) { + log.Printf("%v\n", req.URL) + T("index.html").Execute(c, map[string]interface{}{}) +} + +func loginHandler(c http.ResponseWriter, req *http.Request) { + pwAttempt := req.FormValue("passwd") + log.Printf("%v\n", pwAttempt) + T("login.html").Execute(c, map[string]interface{}{}) +} diff --git a/main.go b/main.go index c8110bf..e8d70d8 100644 --- a/main.go +++ b/main.go @@ -9,7 +9,6 @@ import ( "html/template" "log" "net/http" - "path/filepath" ) var addr = flag.String("addr", ":8000", "address I'll listen on.") @@ -21,16 +20,6 @@ var add_pw = flag.String("passwd", "", "add this pass to the db") var store = sessions.NewCookieStore([]byte("hello world")) var templates *template.Template -func homeHandler(c http.ResponseWriter, req *http.Request) { - log.Printf("%v\n", req.URL) - t := T("index.html") - if t != nil { - t.Execute(c, req.Host) - } else { - log.Fatal("template index.html not found") - } -} - func main() { flag.Parse() if *add_pw != "" { @@ -50,15 +39,8 @@ func main() { log.Fatal(err) } } else { - 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("/login", loginHandler) http.Handle("/s/", http.StripPrefix("/s/", http.FileServer(http.Dir(*static_files)))) if err := http.ListenAndServe(*addr, nil); err != nil { diff --git a/templates/index.html b/templates/index.html index bb69752..95b24dc 100644 --- a/templates/index.html +++ b/templates/index.html @@ -1,17 +1,7 @@ {{ define "title" }}Welcome{{ end }} {{ define "content" }} -
-
-
-
- - - - - -
-
-
-
+
+ This will have stuff +
{{ end }}