Raspberry Pi alarm clock server.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
1.1 KiB

package sonar
import (
// Abort with an error.
func (s *Sonar) Abort(r *http.Request, w http.ResponseWriter, message string, v ...interface{}) {
fmt.Fprintf(w, message, v...)
// FlashAndRedirect to flash and redirect away.
func (s *Sonar) FlashAndRedirect(r *http.Request, w http.ResponseWriter, url string, flash string, v ...interface{}) {
log.Debug("Flash: %s", fmt.Sprintf(flash, v...))
s.Flash(r, w, fmt.Sprintf(flash, v...))
w.Header().Add("Location", url)
// Flash a message to the user.
func (s *Sonar) Flash(r *http.Request, w http.ResponseWriter, tmpl string, v ...string) {
session, _ := s.sessions.Get(r, s.Config.CookieName)
session.AddFlash(tmpl, v...)
session.Save(r, w)
// GetFlashes retrieves the flashed messages.
func (s *Sonar) GetFlashes(r *http.Request, w http.ResponseWriter) []string {
var result []string
session, _ := s.sessions.Get(r, s.Config.CookieName)
if flashes := session.Flashes(); len(flashes) > 0 {
for _, flash := range flashes {
result = append(result, flash.(string))
session.Save(r, w)
return result