本文整理汇总了Golang中vendor/github.com/garyburd/twister/web.Request类的典型用法代码示例。如果您正苦于以下问题:Golang Request类的具体用法?Golang Request怎么用?Golang Request使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Request类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: feedHandler
func feedHandler(req *web.Request) {
if !feedburner.Match([]byte(req.Header.Get(web.HeaderUserAgent))) {
// Not Feedburner
if "" == req.Param.Get("no_fb") {
// And nothing saying to ignore
req.Respond(web.StatusMovedPermanently, web.HeaderLocation, feedburnerUrl)
return
}
}
posts, err := posts.FindLatest(10)
if err != nil {
logger.Printf("failed getting posts for feed: %s", err)
serverError(req, err)
} else {
w := req.Respond(web.StatusOK, web.HeaderContentType, "application/rss+xml; charset=utf-8")
view.RenderPartial(w, "feed.tmpl", &view.RenderInfo{
Post: posts,
SiteTitle: config.SiteTitle,
SiteDescription: config.SiteDescription,
SiteContact: config.SiteContact,
SiteAuthor: config.SiteAuthor,
})
}
}
示例2: permalinkHandler
func permalinkHandler(req *web.Request) {
slug := req.URLParam["slug"]
year, month, day := req.URLParam["year"], req.URLParam["month"], req.URLParam["day"]
y, _ := strconv.Atoi(year)
m, _ := strconv.Atoi(month)
d, _ := strconv.Atoi(day)
post, err := posts.FindByPermalink(y, time.Month(m), d, slug)
if err != nil {
switch err.(type) {
case errors.NotFound:
notFound(req)
default:
logger.Printf("failed finding post with year(%#v) month(%#v) day(%#v) slug(%#v): %s (%T)", year, month, day, slug, err, err)
serverError(req, err)
}
} else {
w := req.Respond(web.StatusOK, web.HeaderContentType, "text/html; charset=utf-8")
view.RenderLayout(w, &view.RenderInfo{
Post: post,
Title: post.Title,
Canonical: view.PostCanonical(post),
Description: post.Description,
})
}
}
示例3: notFound
func notFound(req *web.Request) {
w := req.Respond(web.StatusNotFound, web.HeaderContentType, "text/html; charset=utf-8")
view.RenderLayout(w, &view.RenderInfo{
NotFound: true,
Title: "Not Found",
})
}
示例4: serverError
func serverError(req *web.Request, err error) {
w := req.Respond(web.StatusInternalServerError, web.HeaderContentType, "text/html; charset=utf-8")
view.RenderLayout(w, &view.RenderInfo{
Error: true,
Title: "Oh. Sorry about that.",
})
}
示例5: sitemapHandler
func sitemapHandler(req *web.Request) {
posts, err := posts.FindLatest(posts.Len())
if err != nil {
logger.Printf("failed getting posts for sitemap: %s", err)
serverError(req, err)
} else {
w := req.Respond(web.StatusOK, web.HeaderContentType, "application/xml; charset=utf-8")
view.RenderPartial(w, "sitemap.tmpl", &view.RenderInfo{Post: posts})
}
}
示例6: rootHandler
func rootHandler(req *web.Request) {
posts, err := posts.FindLatest(6)
if err != nil {
logger.Printf("failed finding latest posts: %s", err)
serverError(req, err)
} else {
w := req.Respond(web.StatusOK, web.HeaderContentType, "text/html; charset=utf-8")
view.RenderLayout(w, &view.RenderInfo{
PostPreview: posts,
Canonical: "/",
ArchiveLinks: true,
Description: config.SiteDescription,
})
}
}
示例7: searchHandler
func searchHandler(req *web.Request) {
query := req.Param.Get("query")
posts, err := posts.Search(query)
if err != nil {
logger.Printf("failed finding posts with query %#v: %s", query, err)
serverError(req, err)
} else {
w := req.Respond(web.StatusOK, web.HeaderContentType, "text/html; charset=utf-8")
title := fmt.Sprintf("Search results for %#v", query)
view.RenderLayout(w, &view.RenderInfo{
PostPreview: posts,
Title: title,
PageTitle: title,
ArchiveLinks: true,
})
}
}
示例8: fullArchiveHandler
func fullArchiveHandler(req *web.Request) {
posts, err := posts.FindLatest(posts.Len())
if err != nil {
logger.Printf("failed getting posts for full archive: %s", err)
serverError(req, err)
} else {
w := req.Respond(web.StatusOK, web.HeaderContentType, "text/html; charset=utf-8")
title := "Full archives"
view.RenderLayout(w, &view.RenderInfo{
FullArchive: posts,
Description: title,
Title: title,
ArchiveLinks: true,
Canonical: req.URL.Path,
})
}
}
示例9: tagHandler
func tagHandler(req *web.Request) {
tag := req.URLParam["tag"]
posts, err := posts.FindByTag(tag)
if err != nil {
logger.Printf("failed finding posts with tag %#v: %s", tag, err)
serverError(req, err)
} else {
w := req.Respond(web.StatusOK, web.HeaderContentType, "text/html; charset=utf-8")
title := fmt.Sprintf("Articles tagged with %#v", tag)
view.RenderLayout(w, &view.RenderInfo{
PostPreview: posts,
Title: title,
PageTitle: title,
Canonical: req.URL.Path,
Description: fmt.Sprintf("Articles with the %#v tag", tag),
})
}
}
示例10: categoryHandler
func categoryHandler(req *web.Request) {
category := req.URLParam["category"]
posts, err := posts.FindByCategory(category)
if err != nil {
logger.Printf("failed finding posts with category %#v: %s", category, err)
serverError(req, err)
} else {
w := req.Respond(web.StatusOK, web.HeaderContentType, "text/html; charset=utf-8")
category = strings.Title(category)
title := fmt.Sprintf("%s Articles", category)
view.RenderLayout(w, &view.RenderInfo{
PostPreview: posts,
Title: title,
PageTitle: title,
Canonical: req.URL.Path,
Description: fmt.Sprintf("Articles in the %s category", category),
})
}
}
示例11: monthlyHandler
func monthlyHandler(req *web.Request) {
year, month := req.URLParam["year"], req.URLParam["month"]
y, _ := strconv.Atoi(year)
m, _ := strconv.Atoi(month)
posts, err := posts.FindByMonth(y, time.Month(m))
if err != nil {
logger.Printf("failed finding posts in month %#v of %#v: %s", month, year, err)
serverError(req, err)
} else {
w := req.Respond(web.StatusOK, web.HeaderContentType, "text/html; charset=utf-8")
title := fmt.Sprintf("Archives for %s-%s", month, year)
view.RenderLayout(w, &view.RenderInfo{
PostPreview: posts,
Title: title,
Canonical: req.URL.Path,
ArchiveLinks: true,
Description: title,
})
}
}
示例12: pageHandler
func pageHandler(req *web.Request) {
slug := req.URLParam["slug"]
page, err := pages.FindBySlug(slug)
if err != nil {
switch err.(type) {
case errors.NotFound:
notFound(req)
default:
logger.Printf("failed finding page with slug %#v: %s (%T)", slug, err, err)
serverError(req, err)
}
} else {
w := req.Respond(web.StatusOK, web.HeaderContentType, "text/html; charset=utf-8")
view.RenderLayout(w, &view.RenderInfo{
Page: page,
Title: page.Title,
Canonical: view.PageCanonical(page),
Description: page.Description,
})
}
}
示例13: categoryArchiveHandler
func categoryArchiveHandler(req *web.Request) {
posts, err := posts.FindLatest(posts.Len())
if err != nil {
logger.Printf("failed getting posts for category archive: %s", err)
serverError(req, err)
} else {
grouped := make(map[string][]*post.Post)
for _, post := range posts {
key := post.Category
grouped[key] = append(grouped[key], post)
}
w := req.Respond(web.StatusOK, web.HeaderContentType, "text/html; charset=utf-8")
view.RenderLayout(w, &view.RenderInfo{
CategoryArchive: grouped,
Description: "Archives by category",
Title: "Category archives",
ArchiveLinks: true,
Canonical: req.URL.Path,
})
}
}
示例14: monthlyArchiveHandler
func monthlyArchiveHandler(req *web.Request) {
posts, err := posts.FindLatest(posts.Len())
if err != nil {
logger.Printf("failed getting posts for monthly archive: %s", err)
serverError(req, err)
} else {
grouped := make(map[int64][]*post.Post)
for _, post := range posts {
t := post.PublishedOn
key := -time.Date(t.Year(), t.Month(), 1, 0, 0, 0, 0, time.Local).Unix()
grouped[key] = append(grouped[key], post)
}
w := req.Respond(web.StatusOK, web.HeaderContentType, "text/html; charset=utf-8")
view.RenderLayout(w, &view.RenderInfo{
MonthlyArchive: grouped,
Description: "Archives by month",
Title: "Monthly archives",
ArchiveLinks: true,
Canonical: req.URL.Path,
})
}
}
示例15: opensearchHandler
func opensearchHandler(req *web.Request) {
w := req.Respond(web.StatusOK, web.HeaderContentType, "application/xml; charset=utf-8")
view.RenderPartial(w, "opensearch.tmpl", nil)
}