cookie

package module
v0.0.0-...-6406de4 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2022 License: MIT Imports: 12 Imported by: 0

README

Functions related to cookies.

General information

Documentation

Index

Constants

View Source
const (
	// Version number. Stable API within major version numbers.
	Version = 2.0

	// DefaultCookieTime represent how long login cookies should last, by deafault
	DefaultCookieTime = 24 * 3600 // 24 hours
)

Variables

This section is empty.

Functions

func ClearCookie

func ClearCookie(w http.ResponseWriter, cookieName, cookiePath string)

ClearCookie clears the cookie with the given cookie name and a corresponding path. The cookie is cleared by setting the expiration date to 1970-01-01. Note that browsers *may* be configured to not delete the cookie.

func RandomCookieFriendlyString

func RandomCookieFriendlyString(length int) string

RandomCookieFriendlyString generates a random, but cookie-friendly, string of the given length.

func RandomHumanFriendlyString

func RandomHumanFriendlyString(length int) string

RandomHumanFriendlyString generates a random, but human-friendly, string of

  • the given length. It should be possible to read out loud and send in an email
  • without problems. The string alternates between vowels and consontants. *
  • Google Translate believes the output is Samoan. *
  • Example output for length 10: ookeouvapu

func RandomString

func RandomString(length int) string

RandomString generates a random string of a given length.

func SecureCookie

func SecureCookie(req *http.Request, name, cookieSecret string) (string, bool)

SecureCookie retrieves a secure cookie from a HTTP request

func Seed

func Seed()

Seed the random number generator. One of many possible ways.

func SetCookiePath

func SetCookiePath(w http.ResponseWriter, name, value string, age int64, path string)

SetCookiePath sets a cookie with an explicit path. age is the time-to-live, in seconds (0 means forever).

func SetCookiePathWithFlags

func SetCookiePathWithFlags(w http.ResponseWriter, name, value string, age int64, path string, secure, httponly bool)

SetCookiePathWithFlags sets a cookie with an explicit path.

func SetHeader

func SetHeader(w http.ResponseWriter, hdr, val string, unique bool)

SetHeader sets cookies in the HTTP header

func SetSecureCookiePath

func SetSecureCookiePath(w http.ResponseWriter, name, val string, age int64, path string, cookieSecret string)

SetSecureCookiePath creates and sets a secure cookie with an explicit path. age is the time-to-live, in seconds (0 means forever).

func SetSecureCookiePathWithFlags

func SetSecureCookiePathWithFlags(w http.ResponseWriter, name, val string, age int64, path, cookieSecret string, secure, httponly bool)

SetSecureCookiePathWithFlags creates and sets a secure cookie with an explicit path.

func Signature

func Signature(key string, val []byte, timestamp string) string

Signature retrieves the cookie signature

Types

This section is empty.

Jump to

Keyboard shortcuts

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