cookies

package
v0.2.6 Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2024 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package cookies provides a cookie monster to make and eat all your cookies

Index

Constants

This section is empty.

Variables

View Source
var DebugOnlyCookieConfig = CookieConfig{
	Name:     "datum-debug-cookie",
	Path:     "/",
	MaxAge:   maxAge,
	HTTPOnly: true,
	Secure:   false,
	SameSite: http.SameSiteLaxMode,
}

DebugOnlyCookieConfig configures non-HTTPS cookies; for development only

View Source
var DefaultCookieConfig = CookieConfig{
	Name:     "datum-temporary-cookie",
	Path:     "/",
	Domain:   "",
	MaxAge:   maxAge,
	HTTPOnly: true,
	Secure:   true,
	SameSite: http.SameSiteStrictMode,
}

DefaultCookieConfig configures short-lived temporary http.Cookie creation

Functions

func CookieExpired

func CookieExpired(cookie *http.Cookie) bool

CookieExpired checks to see if a cookie is expired

func GetCookie

func GetCookie(r *http.Request, cookieName string) (*http.Cookie, error)

GetCookie function retrieves a specific cookie from an HTTP request

func NewCookie

func NewCookie(config CookieConfig, value string) *http.Cookie

NewCookie returns a new http.Cookie with the given value and CookieConfig properties

func RemoveCookie

func RemoveCookie(w http.ResponseWriter, cookieName string, v CookieConfig)

RemoveCookie function removes a cookie from the HTTP response

func SetCookie

func SetCookie(w http.ResponseWriter, value string, cookieName string, v CookieConfig)

SetCookie function sets a cookie with the given value and name

func SetCookieB64

func SetCookieB64(w http.ResponseWriter, body []byte, cookieName string, v CookieConfig) string

SetCookieB64 function sets a base64-encoded cookie with the given name and value in the HTTP response

Types

type CookieConfig

type CookieConfig struct {
	// Name is the desired cookie name
	Name string
	// Domain sets the cookie domain. Defaults to the host name of the responding
	// server when left zero valued
	Domain string
	// Path sets the cookie path. Defaults to the path of the URL responding to
	// the request when left zero valued
	Path string
	// MaxAge=0 means no 'Max-Age' attribute should be set
	// MaxAge<0 means delete cookie now, equivalently 'Max-Age: 0'
	// MaxAge>0 means Max-Age attribute present and given in seconds
	// Cookie 'Expires' will be set (or left unset) according to MaxAge
	MaxAge int
	// HTTPOnly indicates whether the browser should prohibit a cookie from
	// being accessible via Javascript. Recommended true.
	HTTPOnly bool
	// Secure flag indicating to the browser that the cookie should only be
	// transmitted over a TLS HTTPS connection. Recommended true in production
	Secure bool
	// SameSite attribute modes indicates that a browser not send a cookie in
	// cross-site requests
	SameSite http.SameSite
}

CookieConfig configures http.Cookie creation

Jump to

Keyboard shortcuts

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