infra
/
goutils
Archived
1
0
Fork 0
This repository has been archived on 2022-04-06. You can view files and clone it, but cannot push or open issues or pull requests.
goutils/http/cookie.go

27 lines
508 B
Go

package http
import (
"time"
"net/http"
)
func SetCookieValue(w http.ResponseWriter, host, key, newCookieValue string) {
http.SetCookie(w,
&http.Cookie{
Name: key,
Value: newCookieValue,
Path: "/",
Domain: host,
Expires: time.Now().UTC().AddDate(3, 0, 0),
Secure: true,
HttpOnly: true,
},
)
}
func GetCookieValue(req *http.Request, name string) (cookieValue string) {
if cookie, _ := req.Cookie(name); cookie != nil {
cookieValue = cookie.Value
}
return
}