Example #1
0
func GetComicView(w http.ResponseWriter, r *http.Request) {
	db, err := models.NewConnect(dbPath)
	defer db.Close()

	n := r.URL.Query().Get(":id")
	id, err := strconv.ParseInt(n, 10, 64)
	if err != nil {
		fmt.Printf("%p", err)
		http.NotFound(w, r)
		return
	}
	c, err := models.GetComic(db, id)
	if err != nil {
		fmt.Printf("%p", err)
		http.NotFound(w, r)
		return
	}
	prev, _ := models.PrevComic(db, id)
	next, _ := models.NextComic(db, id)
	if prev == nil {
		prev = &models.Comic{}
	}
	if next == nil {
		next = &models.Comic{}
	}
	data := struct {
		Comic, Prev, Next *models.Comic
	}{c, prev, next}
	renderTemplate(w, data, tplName, tplPath)
}
Example #2
0
func getComic(w http.ResponseWriter, r *http.Request, db *sql.DB, n int64) (
	c *models.Comic, err error,
) {
	c, err = models.GetComic(db, n)
	if err != nil {
		fmt.Printf("%p", err)
		http.NotFound(w, r)
		return
	}
	return
}