sessions

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: May 22, 2017 License: Apache-2.0 Imports: 7 Imported by: 0

README

Sessions

Package that will be used across Unaxiom to generate and maintain sessions.

Installation

go get -u github.com/Unaxiom/sessions

Usage

import (
    "github.com/Unaxiom/sessions"
    "github.com/Unaxiom/ulogger"
    "gopkg.in/jackc/pgx.v2"
)

func init() {
    // Set up the database and the logger objects
    sessionExpiryTime := int64(86400)
    localTimeZone := "UTC"
    sessions.Setup(dbObject, uloggerObject, sessionExpiryTime, localTimeZone)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DeleteSession

func DeleteSession(sessionToken string) error

DeleteSession deletes the session with the specific sessionToken and returns an error, if any.

func Setup

func Setup(dbParent *pgx.ConnPool, logParent *ulogger.Logger, sessionExpiresInSecs int64, sessionLocalTimezoneName string)

Setup accepts a db conn pool, a ulogger instance, number of seconds after which the session expires (if set to 0, default value of 86400 is used), the timezone (if set to "", default timezone - UTC is used), and sets up the required variables. It also starts the expiry timers of existing sessions.

func TableSessions

func TableSessions(tx *pgx.Tx, defaultSchema string, database string) *schemamagic.Table

TableSessions creates the Sessions table

Types

type Session

type Session struct {
	// ID stores the bigserial (PostgreSQL row id) associated with this session
	ID int64 `json:"id,omitempty"`
	// Key stores the string that needs to be encoded/hashed to generate a unique session value
	Key string `json:"key,omitempty"`
	// Token stores the computed token using the key
	Token string `json:"token,omitempty"`
	// ExpiryIn stores the number of seconds after which this session will expire
	ExpiryIn int64 `json:"expiry_in,omitempty"`
	// ExpiresAt stores the timestamp (with full timezone) at which this session will expire
	ExpiresAt time.Time `json:"expires_at,omitempty"`
	// IP stores the IP address of the client requesting a new session
	IP string `json:"ip,omitempty"`
	// Active stores whether this session is active
	Active bool `json:"active,omitempty"`
	// Timestamp stores the timestamp in epoch secs when this entry was created
	Timestamp int64 `json:"timestamp,omitempty"`
}

Session stores the parameters in the sessions table

func CheckStatus

func CheckStatus(sessionToken string) (Session, error)

CheckStatus accepts a session token, and returns the session object, along with an error, if any

func FetchAllSessions

func FetchAllSessions() ([]Session, error)

FetchAllSessions returns all the live sessions.

func FetchSessionData

func FetchSessionData(session Session) (Session, error)

FetchSessionData returns the data of the particular session token

func NewSession

func NewSession(key string, ipAddress string) (Session, error)

NewSession accepts the key to encode, along with the client's IP Address, inserts into the sessions table, sets the delete session timer, and returns a Session struct.

Jump to

Keyboard shortcuts

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