package web import ( "net/http" "time" ) func (ws *WebServer) LogoutHandler(w http.ResponseWriter, r *http.Request) { cookie, err := r.Cookie("session_id") if err != nil { http.Error(w, "No session found", http.StatusUnauthorized) return } delete(ws.sessions, cookie.Value) http.SetCookie(w, &http.Cookie{ Name: "session_id", Value: "", Path: "/", HttpOnly: true, Expires: <-time.After(time.Second * 1), }) http.Redirect(w, r, "/", http.StatusSeeOther) }