本文整理匯總了Golang中github.com/fuxiaohei/GoInk.Context.ContentType方法的典型用法代碼示例。如果您正苦於以下問題:Golang Context.ContentType方法的具體用法?Golang Context.ContentType怎麽用?Golang Context.ContentType使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/fuxiaohei/GoInk.Context
的用法示例。
在下文中一共展示了Context.ContentType方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Rss
func Rss(ctx *GoInk.Context) {
baseUrl := model.GetSetting("site_url")
article, _ := model.GetPublishArticleList(1, 20)
author := model.GetUsersByRole("ADMIN")[0]
articleMap := make([]map[string]string, len(article))
for i, a := range article {
m := make(map[string]string)
m["Title"] = a.Title
m["Link"] = strings.Replace(baseUrl+a.Link(), baseUrl+"/", baseUrl, -1)
m["Author"] = author.Nick
str := utils.Markdown2Html(a.Content())
str = strings.Replace(str, `src="/`, `src="`+strings.TrimSuffix(baseUrl, "/")+"/", -1)
str = strings.Replace(str, `href="/`, `href="`+strings.TrimSuffix(baseUrl, "/")+"/", -1)
m["Desc"] = str
m["Created"] = time.Unix(a.CreateTime, 0).Format(time.RFC822)
articleMap[i] = m
}
ctx.ContentType("application/rss+xml;charset=UTF-8")
bytes, e := ctx.App().View().Render("rss.xml", map[string]interface{}{
"Title": model.GetSetting("site_title"),
"Link": baseUrl,
"Desc": model.GetSetting("site_description"),
"Created": time.Unix(utils.Now(), 0).Format(time.RFC822),
"Articles": articleMap,
})
if e != nil {
panic(e)
}
ctx.Body = bytes
}
示例2: SiteMap
func SiteMap(ctx *GoInk.Context) {
baseUrl := model.GetSetting("site_url")
println(baseUrl)
article, _ := model.GetPublishArticleList(1, 50)
navigators := model.GetNavigators()
now := time.Unix(utils.Now(), 0).Format(time.RFC3339)
articleMap := make([]map[string]string, len(article))
for i, a := range article {
m := make(map[string]string)
m["Link"] = strings.Replace(baseUrl+a.Link(), baseUrl+"/", baseUrl, -1)
m["Created"] = time.Unix(a.CreateTime, 0).Format(time.RFC3339)
articleMap[i] = m
}
navMap := make([]map[string]string, 0)
for _, n := range navigators {
m := make(map[string]string)
if n.Link == "/" {
continue
}
if strings.HasPrefix(n.Link, "/") {
m["Link"] = strings.Replace(baseUrl+n.Link, baseUrl+"/", baseUrl, -1)
} else {
m["Link"] = n.Link
}
m["Created"] = now
navMap = append(navMap, m)
}
ctx.ContentType("text/xml")
bytes, e := ctx.App().View().Render("sitemap.xml", map[string]interface{}{
"Title": model.GetSetting("site_title"),
"Link": baseUrl,
"Created": now,
"Articles": articleMap,
"Navigators": navMap,
})
if e != nil {
panic(e)
}
ctx.Body = bytes
}