sessions

package module
v2.0.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2018 License: Apache-2.0 Imports: 8 Imported by: 0

README

Sessions

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

v2

Package has been rewritten using a faster in-memory DB. PostgreSQL is no longer required. This version is incompatible with v1.

Installation

go get -u github.com/Unaxiom/sessions

Dependencies
  1. github.com/tidwall/buntdb
  2. github.com/twinj/uuid
Import
import (
    "github.com/Unaxiom/sessions"
)
Usage
sessionExpiryTime := int64(86400)
sessionObject, err := Init("name_of_session", false, sessionExpiryTime)
sessionData, err := sessionObject.NewSession("somekeyhere", "userIPAddress")
fmt.Println("Auth Token is ", sessionData.Token)

// Check the status of the token. An error is returned in case the token does not exist. Returns nil otherwise.
_, err = sessionObject.CheckStatus(sessionData.Token)

// To delete a token
sessionObject.DeleteSession(sessionData.Token)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Session

type Session struct {
	Name       string
	DB         *buntdb.DB
	ExpiryTime int64
}

Session manages all the sessions

func Init added in v1.0.1

func Init(name string, persistSessionToDisk bool, expiryInSecs int64) (*Session, error)

Init initialises a session object with a name, a bool representing if the corresponding file needs to be saved to disk, and a key expiry time in seconds.

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) 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 {
	// 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"`
	// 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