Esempio n. 1
0
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()))
}
Esempio n. 2
0
//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()
}
Esempio n. 3
0
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()
}
Esempio n. 4
0
//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()))
}