diff options
| author | mo khan <mo@mokhan.ca> | 2025-05-07 08:46:32 -0700 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2025-05-07 08:46:32 -0700 |
| commit | f417e03cb09024743baf2f749e4309032afd5f39 (patch) | |
| tree | c2449a35404af96a2395f8716a0901a80c63bf94 /pkg/web/cookie/option.go | |
| parent | d3cb17f8032d95f0f8805a0ce74fe5fc41714bb8 (diff) | |
refactor: delegate to cookie package
Diffstat (limited to 'pkg/web/cookie/option.go')
| -rw-r--r-- | pkg/web/cookie/option.go | 57 |
1 files changed, 0 insertions, 57 deletions
diff --git a/pkg/web/cookie/option.go b/pkg/web/cookie/option.go deleted file mode 100644 index 58a2e93..0000000 --- a/pkg/web/cookie/option.go +++ /dev/null @@ -1,57 +0,0 @@ -package cookie - -import ( - "net/http" - "time" - - "github.com/xlgmokha/x/pkg/x" -) - -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 { - duration := time.Until(expires).Round(time.Second) - c.MaxAge = int(duration.Seconds()) - } - }) -} |
