reprogl
1package session2
3import (4"net/http"5"time"6)
7
8type internalCookie struct {9name, value, path string10persist bool11}
12
13func WriteSessionCookie(w http.ResponseWriter, name, value, path string) {14cookie := &internalCookie{15name: name,16value: value,17path: path,18}19
20writeCookie(w, cookie, time.Now())21}
22
23func WritePermanentCookie(w http.ResponseWriter, name, value, path string, expiry time.Time) {24cookie := &internalCookie{25name: name,26value: value,27path: path,28persist: true,29}30
31writeCookie(w, cookie, expiry)32}
33
34// DeleteCookie note: Finally, to remove a cookie, the server returns a Set-Cookie header
35// with an expiration date in the past. The server will be successful in removing the
36// cookie only if the Path and the Domain attribute in the Set-Cookie header match the values
37// used when the cookie was created.
38//
39// From: https://www.rfc-editor.org/rfc/rfc6265.html
40func DeleteCookie(w http.ResponseWriter, name, path string) {41cookie := &internalCookie{42name: name,43path: path,44}45
46writeCookie(w, cookie, time.Time{})47}
48
49func (c *internalCookie) Name() string {50return c.name51}
52
53func (c *internalCookie) Path() string {54return c.path55}
56
57func (c *internalCookie) Value() string {58return c.value59}
60
61func (c *internalCookie) Persist() bool {62return c.persist63}
64