Documentation
¶
Overview ¶
Package cookie provides cookie encryption using PASETO
Index ¶
- func SecureCookie() bool
- type Client
- func (c *Client) Decrypt(cookieName, cookieValue string) (*Values, error)
- func (c *Client) Delete(w http.ResponseWriter, cookieName string)
- func (c *Client) Encrypt(cookieName string, expiration time.Time, values *Values) string
- func (c *Client) Read(r *http.Request, cookieName string) (values *Values, found bool, err error)
- func (c *Client) WritePersistentCookie(w http.ResponseWriter, cookieName, domain string, httpOnly bool, ...)
- func (c *Client) WriteSessionCookie(w http.ResponseWriter, cookieName, domain string, httpOnly bool, ...)
- type Key
- type Values
- func (v *Values) Get(key Key, output any) (err error)
- func (v *Values) GetString(key Key) (string, error)
- func (v *Values) GetTime(key Key) (time.Time, error)
- func (v *Values) Set(key Key, value any) error
- func (v *Values) SetString(key Key, value string) *Values
- func (v *Values) SetTime(key Key, value time.Time) *Values
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SecureCookie ¶
func SecureCookie() bool
SecureCookie returns true if the cookie should be secure
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client implements reading and writing encrypted cookies
func New ¶
New returns a new Client keyBase64 must be a base64-encoded string of at least 32 random bytes, used to derived the symmetric key.
func (*Client) Delete ¶
func (c *Client) Delete(w http.ResponseWriter, cookieName string)
Delete deletes a cookie from the response
func (*Client) WritePersistentCookie ¶
func (c *Client) WritePersistentCookie(w http.ResponseWriter, cookieName, domain string, httpOnly bool, sameSite http.SameSite, expiration time.Duration, values *Values)
WritePersistentCookie writes a persistent cookie to the response
func (*Client) WriteSessionCookie ¶
func (c *Client) WriteSessionCookie(w http.ResponseWriter, cookieName, domain string, httpOnly bool, sameSite http.SameSite, values *Values)
WriteSessionCookie writes a session cookie to the response
type Values ¶
type Values struct {
// contains filtered or unexported fields
}
Values holds data to be stored in the cookie
func (*Values) Get ¶
Get gets the given key and writes the value into output (which should be a a pointer), if present by parsing the JSON using encoding/json.
func (*Values) GetString ¶ added in v0.7.2
GetString returns the value for a given key as a string, or error if this is not possible (cannot be a string, or value does not exist)
func (*Values) GetTime ¶ added in v0.7.2
GetTime returns the time for a given key as a string, or error if this is not possible (cannot parse as a time, or value does not exist)
func (*Values) Set ¶
Set sets the key with the specified value. Note that this value needs to be serialisable to JSON using encoding/json. Set will check this and return an error if it is not serialisable.