cookie

package
v0.12.4 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2025 License: GPL-3.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNilRequest    = errors.New("nil request")
	ErrNilAttributes = errors.New("nil cookie attributes")
)

Functions

func DeleteCookies added in v0.9.3

func DeleteCookies(w http.ResponseWriter, attributesList ...*Attributes)

DeleteCookies deletes the cookies

Parameters:

  • w: The HTTP response writer
  • attributesList: The list of attributes of the cookies to delete

func GetTimestampCookie added in v0.9.3

func GetTimestampCookie(
	r *http.Request,
	attributes *Attributes,
) (*time.Time, error)

GetTimestampCookie gets a timestamp cookie

Parameters:

  • r: The HTTP request
  • attributes: The attributes of the cookie

Returns:

  • *time.Time: The value of the cookie, or nil if not found
  • error: An error if something went wrong

func RenovateCookie added in v0.9.3

func RenovateCookie(
	w http.ResponseWriter,
	r *http.Request,
	attributes *Attributes,
	expiresAt time.Time,
	cookieNotFoundFn NotFoundFn,
) error

RenovateCookie creates a new cookie with the same value and a new expiration time

Parameters:

  • w: The HTTP response writer
  • r: The HTTP request
  • attributes: The attributes of the cookie
  • expiresAt: The new expiration time of the cookie
  • cookieNotFoundFn: The function to call if the cookie is not found
  • error: An error if something went wrong

Returns:

  • error: An error if something went wrong

func SetCookie

func SetCookie(
	w http.ResponseWriter,
	attributes *Attributes,
	value string,
	expiresAt time.Time,
)

SetCookie sets a cookie

Parameters:

  • w: The HTTP response writer
  • attributes: The attributes of the cookie
  • value: The value of the cookie
  • expiresAt: The expiration time of the cookie

func SetTimestampCookie added in v0.9.3

func SetTimestampCookie(
	w http.ResponseWriter,
	attributes *Attributes,
	value,
	expiresAt time.Time,
)

SetTimestampCookie sets a cookie with a timestamp

Parameters:

  • w: The HTTP response writer
  • attributes: The attributes of the cookie
  • value: The value of the cookie
  • expiresAt: The expiration time of the cookie

Types

type Attributes

type Attributes struct {
	Name     string
	Path     string
	Domain   string
	Secure   bool
	HTTPOnly bool
	SameSite http.SameSite
}

Attributes is the structure for the attributes of a cookie

type NotFoundFn added in v0.10.0

type NotFoundFn func(
	w http.ResponseWriter,
	attributes *Attributes,
	err error,
) error

NotFoundFn is the function to call when a cookie is not found

Jump to

Keyboard shortcuts

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