summaryrefslogtreecommitdiff
path: root/pkg/web
diff options
context:
space:
mode:
authormo khan <mo@mokhan.ca>2025-04-30 12:05:55 -0600
committermo khan <mo@mokhan.ca>2025-04-30 12:05:55 -0600
commit6dc20979d287652a849e32696fe3a805df1001ae (patch)
treef88bcc9702ac950b3d644b942de73f7b565d440e /pkg/web
parent197ef4ee79e7c4881c5c612115326f4e874c9415 (diff)
refactor: extract cookie options
Diffstat (limited to 'pkg/web')
-rw-r--r--pkg/web/cookie/new.go13
1 files changed, 11 insertions, 2 deletions
diff --git a/pkg/web/cookie/new.go b/pkg/web/cookie/new.go
index d4d0700..a3cb200 100644
--- a/pkg/web/cookie/new.go
+++ b/pkg/web/cookie/new.go
@@ -5,10 +5,13 @@ import (
"time"
"github.com/xlgmokha/x/pkg/env"
+ "gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/pkg/pls"
)
-func New(name, value string, expires time.Time) *http.Cookie {
- return &http.Cookie{
+type CookieOption pls.Option[*http.Cookie]
+
+func New(name, value string, expires time.Time, options ...CookieOption) *http.Cookie {
+ cookie := &http.Cookie{
Name: name,
Value: value, // TODO:: digitally sign the value
Expires: expires,
@@ -19,4 +22,10 @@ func New(name, value string, expires time.Time) *http.Cookie {
SameSite: http.SameSiteStrictMode,
Domain: env.Fetch("HOST", "localhost"),
}
+
+ for _, option := range options {
+ cookie = option(cookie)
+ }
+
+ return cookie
}