cookie

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2024 License: BSD-3-Clause Imports: 5 Imported by: 0

README

go-signed-cookies

Overview

This is a simple, semi-opiniated package for handling signed cookies in Go apps.

It is essentially a higher-level convenience API built on top of github.com/gorilla/securecookie.

To figure out how to use this package, please peruse the source (well under 200 lines) and read the comments.

Secrets

Secrets are expected to be 32 or 64 bytes and in base64 format.

You can generate a secret with:

openssl rand -base64 32 # or 64

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Manager

type Manager struct {
	CurrentSecureCookieInstance  *securecookie.SecureCookie
	PreviousSecureCookieInstance *securecookie.SecureCookie
	SameSite                     http.SameSite // default: http.SameSiteLaxMode
	Path                         string        // default: "/"
}

func NewManager

func NewManager(options ManagerOptions) (*Manager, error)

func (Manager) DeleteCookie

func (m Manager) DeleteCookie(w http.ResponseWriter, key string)

func (Manager) GetCookieValue

func (m Manager) GetCookieValue(r *http.Request, key string) (string, error)

func (Manager) Read

func (m Manager) Read(key string, encodedValue string) (string, error)

func (Manager) SetCookie

func (m Manager) SetCookie(w http.ResponseWriter, r *http.Request, key string, value string) error

func (Manager) Sign

func (m Manager) Sign(key string, value string) (string, error)

type ManagerOptions

type ManagerOptions struct {
	CurrentCookieSecret  string // base64 encoded, 32 or 64 bytes
	PreviousCookieSecret string // base64 encoded, 32 or 64 bytes
	SameSite             http.SameSite
	Path                 string
}

Jump to

Keyboard shortcuts

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