session

package
v0.0.0-...-086cf08 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2019 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultHash = crypto.SHA1

DefaultHash is crypto hash used to makce session ID

View Source
var SessionCookieName = "sid"

SessionCookieName stores name of cookie used to link request with session data

Functions

This section is empty.

Types

type Server

type Server interface {
	CookieValue(name string) (string, bool)
	SetCookieValue(name, value string)
	UserAgent() string
	RemoteAddr() string
}

Server is interface/trates that should be implemented to use this package

type Session

type Session struct {
	Data t.Map
	// contains filtered or unexported fields
}

Session represents single session from one user across requests

func Get

func Get(sid string) (session *Session, ok bool)

Get will return session for specific SID

func New

func New(server Server) *Session

New creates new session, using structure which implements Server interface

func Validate

func Validate(req *http.Request) (*Session, bool)

Validate validates request for session storage returns session ID and true/false for if session found or not

func (*Session) Authorize

func (session *Session) Authorize(salt string)

Authorize marks session as authorized, you can pass sepecific value as "salt"/key. salt/key value should be used in validate call for new sessions ID generation, session id cookie is recreated with different ID to prevent session fixation attacks

func (*Session) CreateCookie

func (session *Session) CreateCookie(salt string)

CreateCookie will create cookie using salt/key

func (*Session) Destroy

func (session *Session) Destroy()

Destroy destroys session data from session storage

func (*Session) ID

func (session *Session) ID() string

ID returns session ID which is equeal to cookie session id

func (*Session) IsAuth

func (session *Session) IsAuth() bool

IsAuth returns true if session is authorized

func (session *Session) Unlink()

Unlink removes unused references to memory, fo example 10k users session is stored in memory but we don't need to hold Server instance, it can be huge

func (*Session) Valid

func (session *Session) Valid(salt, userAgent, remoteAddr string) bool

Valid validates session

Jump to

Keyboard shortcuts

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