Exemplo n.º 1
0
func EditPost(g *gas.Gas, postId string) {
	switch g.Method {
	case "GET":
		row := QuerySinglePost.QueryRow(postId)
		var (
			id           int64
			tag          string
			stamp, title string
			body         string
		)
		err := row.Scan(&id, &stamp, &title, &body, &tag)
		if err != nil {
			log.Printf("blog.EditPost(): %v", err)
			g.ErrorPage(http.StatusServiceUnavailable)
		}

		timestamp, _ := time.Parse("2006-01-02 15:04:05-07", stamp)
		g.Render("blog/editpost", &Post{id, timestamp, title, body, tag})

	case "POST":
		QueryEditPost.Exec(g.FormValue("body"), postId)
		http.Redirect(g.ResponseWriter, g.Request, "/blog/", http.StatusFound)
	}

}
Exemplo n.º 2
0
func Page(g *gas.Gas, page string) {
	pageId, _ := strconv.Atoi(page)
	posts := getPosts(g, pageId)
	if len(posts) < 1 {
		g.ErrorPage(http.StatusNotFound)
	}

	g.Render("blog/index", posts)
}
Exemplo n.º 3
0
func NewPost(g *gas.Gas) {
	switch g.Method {
	case "GET":
		g.Render("blog/newpost", nil)
	case "POST":
		now := time.Now().Format("2006-01-02 15:04:05-07")
		_, err := QueryNewPost.Exec(now, g.FormValue("title"), g.FormValue("body"), g.FormValue("tag"))
		if err != nil {
			log.Print(err)
			return
		}
		http.Redirect(g.ResponseWriter, g.Request, "/blog/", http.StatusFound)
	}
}
Exemplo n.º 4
0
func SinglePost(g *gas.Gas, postId string) {
	row := QuerySinglePost.QueryRow(postId)

	var (
		id    int64
		stamp string
		title string
		body  []byte
		tag   string
	)

	err := row.Scan(&id, &stamp, &title, &body, &tag)
	if err != nil {
		log.Printf("blog.SinglePost(): %v", err)
		g.ErrorPage(http.StatusServiceUnavailable)
	}

	timestamp, _ := time.Parse("2006-01-02 15:04:05-07", stamp)
	g.Render("blog/onepost", &Post{id, timestamp, title, string(blackfriday.MarkdownCommon(body)), tag})
}
Exemplo n.º 5
0
func RSS(g *gas.Gas) {
	g.ResponseWriter.Header().Set("Content-Type", "application/rss+xml")
	g.Render("blog/rss", getPosts(g, "0"))
}
Exemplo n.º 6
0
// TODO: add pagination
func Index(g *gas.Gas) {
	// Note to self: use `SELECT setval('posts_id_seq', currval('posts_id_seq')-1);`
	// when deleting a row so that the index gets set properly

	g.Render("blog/index", getPosts(g, "0"))
}