24 lines
359 B
Go
Executable File
24 lines
359 B
Go
Executable File
package main
|
|
|
|
import (
|
|
"net/http"
|
|
"time"
|
|
)
|
|
|
|
func getCookie(r *http.Request, k string) string {
|
|
c, err := r.Cookie(k)
|
|
if err != nil {
|
|
return ""
|
|
}
|
|
return c.Value
|
|
}
|
|
|
|
func setCookie(w *http.ResponseWriter, k, v string) {
|
|
http.SetCookie(*w, &http.Cookie{
|
|
Name: k,
|
|
Value: v,
|
|
MaxAge: int(time.Now().Unix() + int64(60*60*24)),
|
|
Secure: true,
|
|
})
|
|
}
|