From 10db9dae34f357cbfe37517c0c83c62ca19fe268 Mon Sep 17 00:00:00 2001 From: Las Zenow Date: Wed, 1 Aug 2012 12:11:06 +0200 Subject: [PATCH] Add num of books to front page --- front.html | 1 + trantor.go | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/front.html b/front.html index 72fff32..5cb972e 100644 --- a/front.html +++ b/front.html @@ -3,4 +3,5 @@ +

Search on {{.}} books.

library

diff --git a/trantor.go b/trantor.go index ab99a19..3a41fa3 100644 --- a/trantor.go +++ b/trantor.go @@ -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) }