How to delete cookie

Cookies are keyed by name, so when you "change" the name, you actually "create" a different cookie, already expired.

Keep the name the same and it should work, but don't forget to take some time one day to read about cookies and how they work.


To delete a cookie named "storage", sending set-cookie with the same cookie name.

deleteCookieHandler() should be as follows

c := &http.Cookie{
    Name:     "storage",
    Value:    "",
    Path:     "/",
    Expires: time.Unix(0, 0),

    HttpOnly: true,
}

http.SetCookie(rw, c)

MaxAge=0 means no 'Max-Age' attribute specified.

MaxAge<0 means delete cookie now, equivalently 'Max-Age: 0'

MaxAge>0 means Max-Age attribute present and given in seconds

c := &http.Cookie{
    Name:     "storage",
    Value:    "",
    Path:     "/",
    MaxAge:   -1,
    HttpOnly: true,
}

http.SetCookie(rw, c)

Tags:

Cookies

Go