cookie

package
v0.7.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 20, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package cookie provides cookie encryption using PASETO

Index

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

func New(keyBase64 string) (*Client, error)

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) Decrypt

func (c *Client) Decrypt(cookieName, cookieValue string) (Values, error)

Decrypt decrypts a cookie and returns the values

func (*Client) Delete

func (c *Client) Delete(w http.ResponseWriter, cookieName string)

Delete deletes a cookie from the response

func (*Client) Encrypt

func (c *Client) Encrypt(cookieName string, expiration time.Time, cval Values) string

Encrypt encrypts a cookie and returns the value

func (*Client) Read

func (c *Client) Read(r *http.Request, cookieName string) (params Values, found bool, err error)

Read reads the cookie from the request

func (*Client) WritePersistentCookie

func (c *Client) WritePersistentCookie(w http.ResponseWriter, cookieName, domain string, httpOnly bool, sameSite http.SameSite, expiration time.Duration, cval 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, cval Values)

WriteSessionCookie writes a session cookie to the response

type Key

type Key string

Key is a type for storing values in a cookie

type Values

type Values struct {
	// contains filtered or unexported fields
}

Values is a map of cookie values

func NewValues

func NewValues() Values

NewValues initializes a new Values type

func (Values) Delete

func (c Values) Delete(key Key) Values

Delete deletes the value of the cookie

func (Values) Get

func (c Values) Get(key Key) string

Get returns the value of the cookie

func (Values) Has

func (c Values) Has(key Key) bool

Has returns wether or not the key exists

func (Values) Len

func (c Values) Len() int

Len returns the number of values set

func (Values) Set

func (c Values) Set(key Key, value string) Values

Set sets the value of the cookie

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL