cookie

package
v0.16.3 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrBadCookie = errors.New("cookie has a malformed syntax")

Functions

func Parse

func Parse(jar Jar, data string) (err error)

Parse parses cookies, received from a user-agent. These are basically key-value pairs, so the function isn't applicable for Set-Cookie values

Types

type Builder

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

func Build

func Build(name, value string) Builder

Build is a chainable constructor for cookies. A preferred way of instantiation

func (Builder) Cookie

func (b Builder) Cookie() Cookie

Cookie returns the built cookie instance

func (Builder) Domain

func (b Builder) Domain(domain string) Builder

func (Builder) Expires

func (b Builder) Expires(expires time.Time) Builder

func (Builder) HttpOnly

func (b Builder) HttpOnly(httpOnly bool) Builder

func (Builder) MaxAge

func (b Builder) MaxAge(maxAge int) Builder

MaxAge defines a delta in seconds, when the cookie should be dropped. Note, that zero is treated as a zero-value, so will be ignored. In order to be added with a value of zero, it must be negative. -1 is the conventional value for this purpose

func (Builder) Path

func (b Builder) Path(path string) Builder

func (Builder) SameSite

func (b Builder) SameSite(sameSite SameSite) Builder

func (Builder) Secure

func (b Builder) Secure(secure bool) Builder
type Cookie struct {
	Name    string
	Value   string
	Path    string
	Domain  string
	Expires time.Time
	// MaxAge defines a delta in seconds, when the cookie should be dropped.
	// Note, that zero is treated as a zero-value, so will be ignored. In order
	// to be added with a value of zero, it must be negative. -1 is the conventional
	// value for this purpose
	MaxAge   int
	SameSite SameSite
	Secure   bool
	HttpOnly bool
}

func New

func New(name, value string) Cookie

type Jar

type Jar = *keyvalue.Storage

Jar is a key-value storage for cookies. Key-value pairs consists of strings, not cookie.Cookie, as it would lead to space wasting and require a separate data structure

func NewJar

func NewJar() Jar

func NewJarPreAlloc

func NewJarPreAlloc(n int) Jar

type SameSite

type SameSite = string
const (
	SameSiteLax    SameSite = "Lax"
	SameSiteStrict SameSite = "Strict"
	SameSiteNone   SameSite = "None"
)

Jump to

Keyboard shortcuts

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