當前位置: 首頁>>代碼示例>>Golang>>正文


Golang gas.Gas類代碼示例

本文整理匯總了Golang中gas.Gas的典型用法代碼示例。如果您正苦於以下問題:Golang Gas類的具體用法?Golang Gas怎麽用?Golang Gas使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Gas類的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: getPosts

func getPosts(g *gas.Gas, postId interface{}) []*Post {
	rows, err := QueryPage.Query(postId)

	if err != nil {
		g.ErrorPage(http.StatusServiceUnavailable)
		panic(err)
	}

	posts := []*Post{}
	for rows.Next() {
		// TODO: better way to do this?
		var (
			id    int64
			stamp string
			title string
			body  []byte
			tag   string
		)

		err = rows.Scan(&id, &stamp, &title, &body, &tag)
		if err != nil {
			g.ErrorPage(http.StatusServiceUnavailable)
		}
		timestamp, _ := time.Parse("2006-01-02 15:04:05-07", stamp)
		posts = append(posts, &Post{id, timestamp, title, string(blackfriday.MarkdownCommon(body)), tag})
	}

	return posts
}
開發者ID:moshee,項目名稱:gas-blog,代碼行數:29,代碼來源:blog_new.go

示例2: Page

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)
}
開發者ID:moshee,項目名稱:gas-blog,代碼行數:9,代碼來源:blog_new.go

示例3: SinglePost

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})
}
開發者ID:moshee,項目名稱:gas-blog,代碼行數:20,代碼來源:blog_new.go

示例4: NewPost

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)
	}
}
開發者ID:moshee,項目名稱:gas-blog,代碼行數:14,代碼來源:blog_new.go

示例5: EditPost

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)
	}

}
開發者ID:moshee,項目名稱:gas-blog,代碼行數:25,代碼來源:blog_new.go

示例6: RSS

func RSS(g *gas.Gas) {
	g.ResponseWriter.Header().Set("Content-Type", "application/rss+xml")
	g.Render("blog/rss", getPosts(g, "0"))
}
開發者ID:moshee,項目名稱:gas-blog,代碼行數:4,代碼來源:blog_new.go

示例7: Index

// 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"))
}
開發者ID:moshee,項目名稱:gas-blog,代碼行數:7,代碼來源:blog_new.go


注:本文中的gas.Gas類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。