diff options
| author | mo khan <mo@mokhan.ca> | 2025-04-30 15:20:25 -0600 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2025-04-30 15:20:25 -0600 |
| commit | 0a3bbc641efda807af3e54e7f37b562def35e729 (patch) | |
| tree | 431e3385e2101b844d9190b8d219f1ff7117ead4 /pkg/web/cookie/new.go | |
| parent | 2ed3cc0a1a05c32fb7ecc32b02f3245c078b4baf (diff) | |
test: add test for each cookie option
Diffstat (limited to 'pkg/web/cookie/new.go')
| -rw-r--r-- | pkg/web/cookie/new.go | 49 |
1 files changed, 0 insertions, 49 deletions
diff --git a/pkg/web/cookie/new.go b/pkg/web/cookie/new.go index b809b4e..d762f4f 100644 --- a/pkg/web/cookie/new.go +++ b/pkg/web/cookie/new.go @@ -2,7 +2,6 @@ package cookie import ( "net/http" - "time" "github.com/xlgmokha/x/pkg/env" "github.com/xlgmokha/x/pkg/x" @@ -23,51 +22,3 @@ func New(name, value string, options ...x.Option[*http.Cookie]) *http.Cookie { ) return x.New[*http.Cookie](options...) } - -func With(with func(*http.Cookie)) x.Option[*http.Cookie] { - return func(c *http.Cookie) *http.Cookie { - with(c) - return c - } -} - -func WithPath(value string) x.Option[*http.Cookie] { - return With(func(c *http.Cookie) { - c.Path = value - }) -} - -func WithHttpOnly(value bool) x.Option[*http.Cookie] { - return With(func(c *http.Cookie) { - c.HttpOnly = value - }) -} - -func WithSecure(value bool) x.Option[*http.Cookie] { - return With(func(c *http.Cookie) { - c.Secure = value - }) -} - -func WithDomain(value string) x.Option[*http.Cookie] { - return With(func(c *http.Cookie) { - c.Domain = value - }) -} - -func WithSameSite(value http.SameSite) x.Option[*http.Cookie] { - return With(func(c *http.Cookie) { - c.SameSite = value - }) -} - -func WithExpiration(expires time.Time) x.Option[*http.Cookie] { - return With(func(c *http.Cookie) { - c.Expires = expires - if expires.Before(time.Now()) { - c.MaxAge = -1 - } else { - c.MaxAge = int(time.Until(expires).Seconds()) - } - }) -} |
