本文整理匯總了Golang中github.com/hypertornado/prago.Request.Response方法的典型用法代碼示例。如果您正苦於以下問題:Golang Request.Response方法的具體用法?Golang Request.Response怎麽用?Golang Request.Response使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/hypertornado/prago.Request
的用法示例。
在下文中一共展示了Request.Response方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: DevelopmentRecovery
func DevelopmentRecovery(p *prago.Request, recoveryData interface{}) {
if p.App().DevelopmentMode {
temp, err := template.New("development_error").Parse(developmentErrorTmpl)
if err != nil {
panic(err)
}
byteData := fmt.Sprintf("%s", recoveryData)
buf := new(bytes.Buffer)
err = temp.ExecuteTemplate(buf, "development_error", map[string]interface{}{
"name": byteData,
"subname": "500 Internal Server Error",
"stack": string(debug.Stack()),
})
if err != nil {
panic(err)
}
p.Response().Header().Add("Content-type", "text/html")
p.Response().WriteHeader(500)
p.Response().Write(buf.Bytes())
} else {
p.Response().WriteHeader(500)
p.Response().Write([]byte("We are sorry, some error occured. (500)"))
}
p.Log().Errorln(fmt.Sprintf("500 - error\n%s\nstack:\n", recoveryData))
p.Log().Errorln(string(debug.Stack()))
}
示例2: Sitemap
//Sitemap renders sites sitemap xml file
func Sitemap(request prago.Request, urls []string) {
request.Response().Header().Set("Content-Type", "text/xml")
request.Response().WriteHeader(200)
prev := `<?xml version="1.0" encoding="UTF-8"?><urlset
xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9
http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">`
request.Response().Write([]byte(prev))
for _, v := range urls {
url := fmt.Sprintf("<url><loc>%s</loc></url>", v)
request.Response().Write([]byte(url))
}
after := `</urlset>`
request.Response().Write([]byte(after))
request.SetProcessed()
}
示例3: around
func (s *Sessions) around(request prago.Request, next func()) {
if request.IsProcessed() {
next()
return
}
sessionName := s.app.Data()["appName"].(string)
session, err := s.cookieStore.Get(request.Request(), sessionName)
if err != nil {
request.Log().Errorln("Session not valid")
request.Response().Header().Set("Set-Cookie", sessionName+"=; expires=Thu, 01 Jan 1970 00:00:01 GMT;")
panic(err)
}
flashes := session.Flashes()
if len(flashes) > 0 {
request.SetData("flash_messages", flashes)
prago.Must(session.Save(request.Request(), request.Response()))
}
request.SetData("session", session)
next()
}
示例4: AddFlashMessage
//AddFlashMessage adds flash message to request
func AddFlashMessage(request prago.Request, message string) {
session := request.GetData("session").(*sessions.Session)
session.AddFlash(message)
prago.Must(session.Save(request.Request(), request.Response()))
}