Ejemplo n.º 1
0
func PostHandler(w http.ResponseWriter, r *http.Request) {
	db := model.OpenConn()
	//TODO: cache this result
	//model.TestEmptyDB()
	latestPosts := model.GetPosts(10)
	ctx := m{"posts": latestPosts}
	defer db.Close()
	RenderTemplate(w, "index", ctx)
}
Ejemplo n.º 2
0
func PostHandler(w http.ResponseWriter, r *http.Request) {
	db := model.OpenConn()
	//TODO: cache this result
	//model.TestEmptyDB()
	latestPosts := model.GetPosts(10)
	ctx := m{"latestPosts": latestPosts}
	defer db.Close()
	//var listTmpl = template.Must(template.ParseFiles("tmpl/base.html","tmpl/index.html"))
	//listTmpl.ExecuteTemplate(w,"index", ctx)
	//listTmpl.ExecuteTemplate(w,"base",  nil)
	//listTmpl.Execute(w, nil)
	RenderTemplate(w, "base", ctx)
}
Ejemplo n.º 3
0
Archivo: view.go Proyecto: amaudy/Gooo
func HomeHandler(w http.ResponseWriter, r *http.Request, title string) {
	db := model.OpenConn()
	model.TestEmptyDB(db)
	var p model.Post = model.Post{model.M, 2, "Hello World", "whats up yo", 1, true, time.Now(), time.Now()}
	var p2 model.Post = model.Post{model.M, 2, "Test2", "another test post please ignore", 1, true, time.Now(), time.Now()}
	fmt.Println(p.ModelName())
	atts := introspection.GetStructValues(&p)
	model.InsertIntoDB(atts)
	model.GetPosts(10)
	posts := map[string]interface{}{"p1": introspection.ConvertToMap(p), "p2": introspection.ConvertToMap(p2)}
	ctx := map[string]interface{}{"posts": posts}
	defer db.Close()
	//defer stmt.Close()
	RenderTemplate(w, "index", ctx)
}