summaryrefslogtreecommitdiff
path: root/pkg/web/cookie/reset.go
diff options
context:
space:
mode:
authormo khan <mo@mokhan.ca>2025-04-30 15:06:55 -0600
committermo khan <mo@mokhan.ca>2025-04-30 15:06:55 -0600
commit2ed3cc0a1a05c32fb7ecc32b02f3245c078b4baf (patch)
treebfde739dc56a44088cc165a37d5f703b6e698afd /pkg/web/cookie/reset.go
parent9a21636ce6c7fd4100f18a4319c26c9420f7f6c7 (diff)
refactor: delegate to cookie.Reset to overload with options
Diffstat (limited to 'pkg/web/cookie/reset.go')
-rw-r--r--pkg/web/cookie/reset.go35
1 files changed, 12 insertions, 23 deletions
diff --git a/pkg/web/cookie/reset.go b/pkg/web/cookie/reset.go
index 87e815e..cfb1830 100644
--- a/pkg/web/cookie/reset.go
+++ b/pkg/web/cookie/reset.go
@@ -8,29 +8,18 @@ import (
)
func Reset(name string) *http.Cookie {
- return Clear(&http.Cookie{
- Name: name,
- })
+ return New(
+ name,
+ "",
+ WithExpiration(time.Unix(0, 0)),
+ WithPath("/"),
+ WithHttpOnly(true),
+ WithSecure(true),
+ WithSameSite(http.SameSiteDefaultMode),
+ WithDomain(env.Fetch("HOST", "localhost")),
+ )
}
-func Expire(w http.ResponseWriter, r *http.Request, name string) {
- cookie, err := r.Cookie(name)
- if err != nil {
- http.SetCookie(w, Reset(name))
- } else {
- Clear(cookie)
- http.SetCookie(w, cookie)
- }
-}
-
-func Clear(cookie *http.Cookie) *http.Cookie {
- cookie.Value = ""
- cookie.Expires = time.Unix(0, 0)
- cookie.MaxAge = -1
- cookie.Path = "/"
- cookie.HttpOnly = true
- cookie.Secure = true
- cookie.SameSite = http.SameSiteDefaultMode
- cookie.Domain = env.Fetch("HOST", "localhost")
- return cookie
+func Expire(w http.ResponseWriter, name string) {
+ http.SetCookie(w, Reset(name))
}