cookies

package module
v0.0.0-...-d4da5a7 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2017 License: Apache-2.0 Imports: 4 Imported by: 0

README

cookies

HTTP cookies related utilities, such as encrypted and signed cookies as well as cookie-based sessions

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CookieEncoder

type CookieEncoder interface {
	Encode(v interface{}, c *http.Cookie) error
	Decode(v interface{}, c *http.Cookie) error
}

CookieEncoder encodes/decodes a specific data structure into a cookie's content.

type CookieEncryptor

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

CookieEncryptor implements cookie encryption and signing to allow securely storing sensitive information on the user-agent.

func NewCookieEncryptor

func NewCookieEncryptor(secret string, iterations int) *CookieEncryptor

NewCookieEncryptor creates a new instance of CookieEncryptor. Creating this instance is expensive since it has to derives the keys.

func (*CookieEncryptor) Decrypt

func (ce *CookieEncryptor) Decrypt(cookie *http.Cookie) error

Decrypt takes an encrypted http.Cookie instance and decrypts it.

func (*CookieEncryptor) Encrypt

func (ce *CookieEncryptor) Encrypt(cookie *http.Cookie) error

Encrypt takes an http.Cookie instance and encrypts and sign it's value, replacing it.

type CookieOptions

type CookieOptions struct {
	Domain   string
	Path     string
	HTTPOnly bool
	Secure   bool
	MaxAge   time.Duration
}

type CookieSessionManager

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

CookieSessionManager manages session by storing the session data directly into a secure cookie.

func NewCookieSessionManager

func NewCookieSessionManager(cm *SecureCookieManager, name string, opts *CookieOptions) *CookieSessionManager

NewCookieSessionManager creates a new cookie-based session manager.

func (*CookieSessionManager) Current

func (sm *CookieSessionManager) Current(req *http.Request, sess Session) error

Current fetches the current session from the request cookie, starting one if it doesn't exist.

func (*CookieSessionManager) Update

func (sm *CookieSessionManager) Update(w http.ResponseWriter, req *http.Request, sess Session) error

Update updates the session with the given struct, replacing the existing session data with it.

type JSONCookieEncoder

type JSONCookieEncoder struct{}

JSONCookieEncoder encodes/decodes cookies using encoding/json

func (JSONCookieEncoder) Decode

func (e JSONCookieEncoder) Decode(v interface{}, c *http.Cookie) error

func (JSONCookieEncoder) Encode

func (e JSONCookieEncoder) Encode(v interface{}, c *http.Cookie) error

type SecureCookieManager

type SecureCookieManager struct {
	Encryptor *CookieEncryptor
	Encoder   CookieEncoder
}

func (*SecureCookieManager) Delete

Deletes the Cookie, setting value to empty and expiring in the past.

func (*SecureCookieManager) Get

func (cm *SecureCookieManager) Get(req *http.Request, name string, v interface{}) (*http.Cookie, error)

Get gets the Cookie, decrypted it and deserialized it into v. Returns the decrypted cookie.

func (*SecureCookieManager) Set

func (cm *SecureCookieManager) Set(w http.ResponseWriter, name string, opts *CookieOptions, v interface{}) (*http.Cookie, error)

Set a cookie with the data set to the encrypted version of the serialization of v. Returns the http.Cookie generated.

type Session

type Session interface {
	Validate(*http.Request) error
}

type SessionConstructor

type SessionConstructor func(*http.Request) (Session, error)

type SessionManager

type SessionManager interface {
	Current(*http.Request, Session) error
	Update(http.ResponseWriter, *http.Request, Session) error
}

SessionManager defines the basic interface for different session backends.

Jump to

Keyboard shortcuts

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