本文整理匯總了Golang中net/http.Request.Replace方法的典型用法代碼示例。如果您正苦於以下問題:Golang Request.Replace方法的具體用法?Golang Request.Replace怎麽用?Golang Request.Replace使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類net/http.Request
的用法示例。
在下文中一共展示了Request.Replace方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: postsHandler
func postsHandler(w http.ResponseWriter, r *http.Request, title string) {
log.Print("Title is: " + title)
log.Print(len(strings.Split(title, "/")))
if len(strings.Split(title, "/")) > 2 {
p, err := loadPage(title+".html", config.RootDesc, config.SiteName)
if err != nil {
log.Print(err)
http.Redirect(w, r, "/", http.StatusFound)
return
}
renderTemplate(w, "root", p)
} else {
r := strings.NewReplacer("_", " ")
var data bytes.Buffer
for i := len(posts) - 1; i >= 0; i-- {
s := posts[i]
row := fmt.Sprintf("<p><a href=\"/%s\">%s</a>\n\t\t\t\t<span class=\"blog-post-meta\">%s</span>\n\t\t\t\t</p>\n",
strings.Split(s, ".html")[0], r.Replace(strings.Split(filepath.Base(s), ".html")[0]), dateFromPath(s))
log.Print(s)
data.Write([]byte(row))
}
p := &Page{SiteName: config.SiteName, PageTitle: "blargh", Body: template.HTML(data.String()), PostDate: "N/A", PostTitle: "plupp", Description: config.PostsDesc}
renderTemplate(w, "posts", p)
}
}