summaryrefslogtreecommitdiff
path: root/pkg/web/cookie/new.go
blob: d762f4f903869584505b755522017441a6af6a09 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
package cookie

import (
	"net/http"

	"github.com/xlgmokha/x/pkg/env"
	"github.com/xlgmokha/x/pkg/x"
)

func New(name, value string, options ...x.Option[*http.Cookie]) *http.Cookie {
	options = x.Prepend[x.Option[*http.Cookie]](
		options,
		With(func(c *http.Cookie) {
			c.Name = name
			c.Value = value // TODO:: digitally sign the value
		}),
		WithPath("/"),
		WithHttpOnly(true),
		WithSecure(true),
		WithSameSite(http.SameSiteStrictMode),
		WithDomain(env.Fetch("HOST", "localhost")),
	)
	return x.New[*http.Cookie](options...)
}