cookies

package
v0.1.49 Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound    = errors.New("cookie not found")
	ErrStoreClosed = errors.New("cookie store is closed")
)

Common errors.

Functions

This section is empty.

Types

type Cookie struct {
	ID        string    `json:"id"`
	Domain    string    `json:"domain"`
	Path      string    `json:"path"`
	Name      string    `json:"name"`
	Value     string    `json:"value"`
	Secure    bool      `json:"secure"`
	HttpOnly  bool      `json:"http_only"`
	SameSite  string    `json:"same_site"`
	Expires   time.Time `json:"expires"`
	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
}

Cookie represents a stored cookie with all attributes.

func FromHTTPCookie

func FromHTTPCookie(u *url.URL, hc *http.Cookie) *Cookie

FromHTTPCookie creates a Cookie from http.Cookie and URL.

func (*Cookie) IsExpired

func (c *Cookie) IsExpired() bool

IsExpired returns true if the cookie has expired.

func (*Cookie) IsSession

func (c *Cookie) IsSession() bool

IsSession returns true if this is a session cookie (no expiration).

func (*Cookie) ToHTTPCookie

func (c *Cookie) ToHTTPCookie() *http.Cookie

ToHTTPCookie converts to standard http.Cookie.

type PersistentJar

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

PersistentJar implements http.CookieJar with SQLite persistence.

func NewPersistentJar

func NewPersistentJar(store Store) (*PersistentJar, error)

NewPersistentJar creates a new persistent cookie jar.

func (*PersistentJar) Cleanup

func (pj *PersistentJar) Cleanup() (int64, error)

Cleanup removes expired cookies from the store.

func (*PersistentJar) Clear

func (pj *PersistentJar) Clear() error

Clear removes all cookies from jar and store.

func (*PersistentJar) ClearDomain

func (pj *PersistentJar) ClearDomain(domain string) error

ClearDomain removes all cookies for a domain.

func (*PersistentJar) Cookies

func (pj *PersistentJar) Cookies(u *url.URL) []*http.Cookie

Cookies implements http.CookieJar.

func (*PersistentJar) Count

func (pj *PersistentJar) Count() (int64, error)

Count returns the number of stored cookies.

func (*PersistentJar) ListAll

func (pj *PersistentJar) ListAll() ([]*Cookie, error)

ListAll returns all stored cookies.

func (*PersistentJar) SetCookies

func (pj *PersistentJar) SetCookies(u *url.URL, cookies []*http.Cookie)

SetCookies implements http.CookieJar.

func (*PersistentJar) Store

func (pj *PersistentJar) Store() Store

Store returns the underlying store (for closing).

type QueryOptions

type QueryOptions struct {
	Domain         string // Filter by domain
	Path           string // Filter by path
	Name           string // Filter by cookie name
	IncludeExpired bool   // Include expired cookies
	Limit          int    // Max results (0 = no limit)
}

QueryOptions for filtering cookies.

type Store

type Store interface {
	// Set stores or updates a cookie.
	Set(ctx context.Context, cookie *Cookie) error

	// Get retrieves a cookie by domain, path, and name.
	Get(ctx context.Context, domain, path, name string) (*Cookie, error)

	// List returns cookies matching the query options.
	List(ctx context.Context, opts QueryOptions) ([]*Cookie, error)

	// Delete removes a specific cookie.
	Delete(ctx context.Context, domain, path, name string) error

	// DeleteByDomain removes all cookies for a domain.
	DeleteByDomain(ctx context.Context, domain string) error

	// DeleteExpired removes all expired cookies and returns count.
	DeleteExpired(ctx context.Context) (int64, error)

	// Clear removes all cookies.
	Clear(ctx context.Context) error

	// Count returns total number of cookies.
	Count(ctx context.Context) (int64, error)

	// Close closes the store.
	Close() error
}

Store defines the interface for cookie persistence.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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