amuz.es/src/infra/goutils@v0.1.3/http/cookie.go (about) 1 package http 2 3 import ( 4 "time" 5 "net/http" 6 ) 7 8 func SetCookieValue(w http.ResponseWriter, host, key, newCookieValue string) { 9 http.SetCookie(w, 10 &http.Cookie{ 11 Name: key, 12 Value: newCookieValue, 13 Path: "/", 14 Domain: host, 15 Expires: time.Now().UTC().AddDate(3, 0, 0), 16 Secure: true, 17 HttpOnly: true, 18 }, 19 ) 20 } 21 func GetCookieValue(req *http.Request, name string) (cookieValue string) { 22 if cookie, _ := req.Cookie(name); cookie != nil { 23 cookieValue = cookie.Value 24 } 25 return 26 }