当前位置: 首页>>代码示例>>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;未经允许,请勿转载。