Add num of books to front page
This commit is contained in:
parent
614ce0309a
commit
10db9dae34
2 changed files with 5 additions and 1 deletions
|
@ -3,4 +3,5 @@
|
||||||
<input type="search" name="q" />
|
<input type="search" name="q" />
|
||||||
<input type="submit" value="Search">
|
<input type="submit" value="Search">
|
||||||
</form>
|
</form>
|
||||||
|
<p>Search on {{.}} books.</p>
|
||||||
<p><img src="/img/library.jpg" alt="library" /></p>
|
<p><img src="/img/library.jpg" alt="library" /></p>
|
||||||
|
|
|
@ -17,6 +17,7 @@ func loadTemplate(w http.ResponseWriter, tmpl string, data interface{}) {
|
||||||
// TODO: when finish devel conver to global:
|
// TODO: when finish devel conver to global:
|
||||||
var templates = template.Must(template.ParseFiles("head.html", "foot.html", "front.html", "book.html", "search.html"))
|
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)
|
err := templates.ExecuteTemplate(w, "head.html", nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
@ -53,12 +54,14 @@ func main() {
|
||||||
}
|
}
|
||||||
defer session.Close()
|
defer session.Close()
|
||||||
coll := session.DB(DB_NAME).C(BOOKS_COLL)
|
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("/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) })
|
http.HandleFunc("/search/", func(w http.ResponseWriter, r *http.Request) { searchHandler(coll, w, r) })
|
||||||
|
// FIXME: shows content
|
||||||
http.HandleFunc("/img/", sendFile)
|
http.HandleFunc("/img/", sendFile)
|
||||||
http.HandleFunc("/cover/", sendFile)
|
http.HandleFunc("/cover/", sendFile)
|
||||||
http.HandleFunc("/books/", 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)
|
http.ListenAndServe(":8080", nil)
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue