|
|
- package Auth
-
- import (
- "net/http"
- "time"
- )
-
- func Logout(w http.ResponseWriter, r *http.Request) {
- var (
- c *http.Cookie
- sessionToken string
- err error
- )
-
- c, err = r.Cookie("session_token")
- if err != nil {
- if err == http.ErrNoCookie {
- w.WriteHeader(http.StatusUnauthorized)
- return
- }
- w.WriteHeader(http.StatusBadRequest)
- return
- }
-
- sessionToken = c.Value
-
- delete(Sessions, sessionToken)
-
- http.SetCookie(w, &http.Cookie{
- Name: "session_token",
- Value: "",
- Expires: time.Now(),
- })
- }
|