Got distinct index and login pages working.
This commit is contained in:
parent
f9d2d247bc
commit
3ca4994676
17
handlers.go
Normal file
17
handlers.go
Normal 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
20
main.go
@ -9,7 +9,6 @@ import (
|
|||||||
"html/template"
|
"html/template"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"path/filepath"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var addr = flag.String("addr", ":8000", "address I'll listen on.")
|
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 store = sessions.NewCookieStore([]byte("hello world"))
|
||||||
var templates *template.Template
|
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() {
|
func main() {
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
if *add_pw != "" {
|
if *add_pw != "" {
|
||||||
@ -50,15 +39,8 @@ func main() {
|
|||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
} else {
|
} 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("/", homeHandler)
|
||||||
|
http.HandleFunc("/login", loginHandler)
|
||||||
http.Handle("/s/", http.StripPrefix("/s/",
|
http.Handle("/s/", http.StripPrefix("/s/",
|
||||||
http.FileServer(http.Dir(*static_files))))
|
http.FileServer(http.Dir(*static_files))))
|
||||||
if err := http.ListenAndServe(*addr, nil); err != nil {
|
if err := http.ListenAndServe(*addr, nil); err != nil {
|
||||||
|
@ -1,17 +1,7 @@
|
|||||||
{{ define "title" }}Welcome{{ end }}
|
{{ define "title" }}Welcome{{ end }}
|
||||||
|
|
||||||
{{ define "content" }}
|
{{ define "content" }}
|
||||||
<div class="container pw">
|
<div class="container pw">
|
||||||
<div class="row-fluid">
|
This will have stuff
|
||||||
<form class="form-inline offset4 span3">
|
</div>
|
||||||
<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>
|
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
Loading…
Reference in New Issue
Block a user