Got distinct index and login pages working.

This commit is contained in:
Stephen McQuay 2013-02-20 21:27:09 -08:00
parent f9d2d247bc
commit 3ca4994676
3 changed files with 21 additions and 32 deletions

17
handlers.go Normal file
View File

@ -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{}{})
}

20
main.go
View File

@ -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 {

View File

@ -1,17 +1,7 @@
{{ define "title" }}Welcome{{ end }}
{{ define "content" }}
<div class="container pw">
<div class="row-fluid">
<form class="form-inline offset4 span3">
<div class="input-prepend input-append span2">
<span class="add-on">
<i class="icon-lock"></i>
</span>
<input type="password" class="" placeholder="password">
<button class="btn" type="button">Sign in</button>
</div>
</form>
</div>
</div>
<div class="container pw">
This will have stuff
</div>
{{ end }}