pg

package
v0.0.0-...-43541b1 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package pg contains postgresql session provider based on jackc connection to PG. Requirements:

jackc connection to PG Sql https://github.com/jackc/pgx
PG_CRYPTO extension must be installed CREATE EXTENSION pgrypto, PGP_SYM_DECRYPT, PGP_SYM_ENCRYPT functions are used,
If encryption is not necessary - correct sql in SessionRead/SessionClose functions
Some SQL scripts are nesessary:
	session_vals.sql contains table for holding session values
	session_vals_process.sql trigger function for updating login information (logins table must be present in database)
	session_vals_trigger.sql creating trigger script

Internally gob encoder is used for data serialization. Session data is read at start and kept in memory SessionStore structure. Session key-value pares are kept in storeValue type.

Index

Constants

View Source
const LOG_PREF = "pg provider:"
View Source
const PROVIDER = "pg"
View Source
const SESS_ID_LEN = 36

Session key ID length. As it is stored it pg data base in varchar column its length is limited.

Variables

View Source
var EKeyNotFound = errors.New("key not found")
View Source
var EValMustBePtr = errors.New("value must be of type ptr")

Functions

This section is empty.

Types

type Provider

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

Provider structure holds provider information.

func (*Provider) DestroyAllSessions

func (pder *Provider) DestroyAllSessions(l io.Writer, logLev session.LogLevel)

func (*Provider) GetMaxIdleTime

func (pder *Provider) GetMaxIdleTime() int64

func (*Provider) GetMaxLifeTime

func (pder *Provider) GetMaxLifeTime() int64

func (*Provider) GetSessionIDLen

func (pder *Provider) GetSessionIDLen() int

func (*Provider) InitProvider

func (pder *Provider) InitProvider(provParams []interface{}) error

InitProvider initializes postgresql provider. Function expects two parameters:

First parameter: *pgxpool.Pool
Second parameter: encryptKey application unique,if to set no encryption used

func (*Provider) NewSessionStore

func (pder *Provider) NewSessionStore(sid string) *SessionStore

func (*Provider) SessionClose

func (pder *Provider) SessionClose(sid string) error

func (*Provider) SessionDestroy

func (pder *Provider) SessionDestroy(sid string) error

SessionDestroy destoys session by its ID.

func (*Provider) SessionGC

func (pder *Provider) SessionGC(l io.Writer, logLev session.LogLevel)

SessionGC clears unused sessions

func (*Provider) SessionInit

func (pder *Provider) SessionInit(sid string) (session.Session, error)

SessionInit initializes session with given ID.

func (*Provider) SessionRead

func (pder *Provider) SessionRead(sid string) (session.Session, error)

SessionRead reads session data from db to memory.

func (*Provider) SetMaxIdleTime

func (pder *Provider) SetMaxIdleTime(maxIdleTime int64)

func (*Provider) SetMaxLifeTime

func (pder *Provider) SetMaxLifeTime(maxLifeTime int64)

type SessionStore

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

SessionStore contains session information.

func (*SessionStore) Delete

func (st *SessionStore) Delete(key string) error

Delete deletes session value from memmory by key. No flushing is done.

func (*SessionStore) Flush

func (st *SessionStore) Flush() error

Flush performs the actual write to database.

func (*SessionStore) Get

func (st *SessionStore) Get(key string, val interface{}) error

Get returns session value by its key. Value is retrieved from memory.

func (*SessionStore) GetBool

func (st *SessionStore) GetBool(key string) bool

GetBool returns bool value by key.

func (*SessionStore) GetDate

func (st *SessionStore) GetDate(key string) time.Time

GetDate returns time.Time value by key.

func (*SessionStore) GetFloat

func (st *SessionStore) GetFloat(key string) float64

GetFloat returns float value by key.

func (*SessionStore) GetInt

func (st *SessionStore) GetInt(key string) int64

GetInt returns int value by key.

func (*SessionStore) GetString

func (st *SessionStore) GetString(key string) string

GetString returns string value by key.

func (*SessionStore) Put

func (st *SessionStore) Put(key string, value interface{}) error

func (*SessionStore) SessionID

func (st *SessionStore) SessionID() string

SessionID returns session unique ID.

func (*SessionStore) Set

func (st *SessionStore) Set(key string, value interface{}) error

Set sets inmemory value. No database flush is done.

func (*SessionStore) TimeAccessed

func (st *SessionStore) TimeAccessed() time.Time

TimeAccessed returns timeAccessed property.

func (*SessionStore) TimeCreated

func (st *SessionStore) TimeCreated() time.Time

TimeCreated returns timeCreated property.

Jump to

Keyboard shortcuts

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