package web import ( "net/http" "github.com/xlgmokha/x/pkg/cookie" "github.com/xlgmokha/x/pkg/x" ) func NewCookie(name, value string, options ...x.Option[*http.Cookie]) *http.Cookie { return x.New[*http.Cookie](x.Prepend[x.Option[*http.Cookie]]( options, cookie.WithName(name), cookie.WithValue(value), cookie.WithPath("/"), cookie.WithHttpOnly(true), cookie.WithSecure(true), )...) } func ExpireCookie(w http.ResponseWriter, name string) error { return WriteCookie(w, cookie.Reset(name, cookie.WithPath("/"), cookie.WithHttpOnly(true), cookie.WithSecure(true), )) } func WriteCookie(w http.ResponseWriter, c *http.Cookie) error { if err := c.Valid(); err != nil { return err } cookie.Write(w, c) return nil }