Add num of books to front page

This commit is contained in:
Las Zenow 2012-08-01 12:11:06 +02:00
parent 614ce0309a
commit 10db9dae34
2 changed files with 5 additions and 1 deletions

View file

@ -3,4 +3,5 @@
<input type="search" name="q" />
<input type="submit" value="Search">
</form>
<p>Search on {{.}} books.</p>
<p><img src="/img/library.jpg" alt="library" /></p>

View file

@ -17,6 +17,7 @@ func loadTemplate(w http.ResponseWriter, tmpl string, data interface{}) {
// TODO: when finish devel conver to global:
var templates = template.Must(template.ParseFiles("head.html", "foot.html", "front.html", "book.html", "search.html"))
// TODO: use includes
err := templates.ExecuteTemplate(w, "head.html", nil)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
@ -53,12 +54,14 @@ func main() {
}
defer session.Close()
coll := session.DB(DB_NAME).C(BOOKS_COLL)
num, _ := coll.Count()
http.HandleFunc("/book/", func(w http.ResponseWriter, r *http.Request) { bookHandler(coll, w, r) })
http.HandleFunc("/search/", func(w http.ResponseWriter, r *http.Request) { searchHandler(coll, w, r) })
// FIXME: shows content
http.HandleFunc("/img/", sendFile)
http.HandleFunc("/cover/", sendFile)
http.HandleFunc("/books/", sendFile)
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { loadTemplate(w, "front", nil) })
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { loadTemplate(w, "front", num) })
http.ListenAndServe(":8080", nil)
}