session

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2023 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Options

type Options struct {
	// The name of the cookie (default is "_session").
	Name string

	// MaxAge of the cookie before expiry (default is 365 days). Set it to
	// -1 for no expiry.
	MaxAge int
}

Options to customize the behaviour of the session.

type Session

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

A Session manages setting and getting data from the cookie that stores the session data.

func New

func New(secret []byte, opts ...Options) *Session

New creates a new session with the given key.

func (*Session) Delete

func (s *Session) Delete(w http.ResponseWriter, r *http.Request, key string) interface{}

Delete deletes and returns the session value with the given key.

func (*Session) Flash

func (s *Session) Flash(w http.ResponseWriter, r *http.Request, key string, value interface{})

Flash sets a flash message on a request.

func (*Session) Flashes

func (s *Session) Flashes(w http.ResponseWriter, r *http.Request) map[string]interface{}

Flashes returns all flash messages, clearing all saved flashes.

func (*Session) Get

func (s *Session) Get(r *http.Request, key string) interface{}

Session creates a new session from the given HTTP request. If the request already has a cookie with an associated session, the session data is created from the cookie. If not, a new session is created.

func (*Session) List

func (s *Session) List(r *http.Request) map[string]interface{}

List returns all key value pairs of session data from the given request.

func (*Session) Reset

func (s *Session) Reset(w http.ResponseWriter, r *http.Request)

Reset resets the session, deleting all values.

func (*Session) Set

func (s *Session) Set(w http.ResponseWriter, r *http.Request, key string, value interface{})

Set sets or updates the given value on the session.

Jump to

Keyboard shortcuts

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