threadr-rewritten/handlers/logout.go

21 lines
674 B
Go

package handlers
import (
"log"
"net/http"
"github.com/gorilla/sessions"
)
func LogoutHandler(app *App) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
session := r.Context().Value("session").(*sessions.Session)
session.Values = make(map[interface{}]interface{})
session.Options.MaxAge = -1
if err := session.Save(r, w); err != nil {
log.Printf("Error saving session in LogoutHandler: %v", err)
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
return
}
http.Redirect(w, r, app.Config.ThreadrDir+"/", http.StatusFound)
}
}