sessions

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2018 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
To create the sessions table
err := SetupTable(applicationName string, orgName string, production bool, dbHost string, dbPort uint16, databaseName string, dbUser string, dbPassword string, defaultSchema string)
Dependencies
  1. github.com/apratheek/schemamagic
  2. github.com/twinj/uuid
  3. gopkg.in/jackc/pgx.v2
To start the sessions process
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"
    sessionObject, err := sessions.Init(sessionExpiresInSecs int64, sessionLocalTimezoneName string, applicationName string, orgName string, production bool, dbHost string, dbPort uint16, databaseName string, dbUser string, dbPassword string)
    sessionData, err := sessionObject.NewSession("somekeyhere", "userIPAddress")
    fmt.Println("Auth Token is ", sessionData.Token)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetupTable added in v1.0.1

func SetupTable(applicationName string, orgName string, production bool, dbHost string, dbPort uint16, databaseName string, dbUser string, dbPassword string, defaultSchema string) error

SetupTable accepts all the parameters and creates/updates the Sessions table. Don't call it along with Init(). Init() and SetupTable() should be called separately.

Types

type Session

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

Session manages all the sessions

func Init added in v1.0.1

func Init(sessionExpiresInSecs int64, sessionLocalTimezoneName string, applicationName string, orgName string, production bool, dbHost string, dbPort uint16, databaseName string, dbUser string, dbPassword string) (*Session, error)

Init accepts 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 (*Session) CheckStatus added in v1.0.1

func (sessionObject *Session) CheckStatus(sessionToken string) (SessionData, error)

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

func (*Session) DeleteSession added in v1.0.1

func (sessionObject *Session) DeleteSession(sessionToken string) error

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

func (*Session) FetchAllSessions added in v1.0.1

func (sessionObject *Session) FetchAllSessions() ([]SessionData, error)

FetchAllSessions returns all the live sessions.

func (*Session) FetchSessionData added in v1.0.1

func (sessionObject *Session) FetchSessionData(session SessionData) (SessionData, error)

FetchSessionData returns the data of the particular session token

func (*Session) NewSession added in v1.0.1

func (sessionObject *Session) NewSession(key string, ipAddress string) (SessionData, 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 SessionData struct.

type SessionData added in v1.0.1

type SessionData 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"`
}

SessionData stores the parameters in the sessions table

Jump to

Keyboard shortcuts

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