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
- Variables
- type Provider
- func (pder *Provider) CloseProvider()
- func (pder *Provider) DestroyAllSessions(l io.Writer, logLev session.LogLevel)
- func (pder *Provider) GetMaxIdleTime() int64
- func (pder *Provider) GetMaxLifeTime() int64
- func (pder *Provider) GetSessionIDLen() int
- func (pder *Provider) InitProvider(provParams []interface{}) error
- func (pder *Provider) NewSessionStore(sid string) *SessionStore
- func (pder *Provider) SessionClose(sid string) error
- func (pder *Provider) SessionDestroy(sid string) error
- func (pder *Provider) SessionGC(l io.Writer, logLev session.LogLevel)
- func (pder *Provider) SessionInit(sid string) (session.Session, error)
- func (pder *Provider) SessionRead(sid string) (session.Session, error)
- func (pder *Provider) SetMaxIdleTime(maxIdleTime int64)
- func (pder *Provider) SetMaxLifeTime(maxLifeTime int64)
- type SessionStore
- func (st *SessionStore) Delete(key string) error
- func (st *SessionStore) Flush() error
- func (st *SessionStore) Get(key string, val interface{}) error
- func (st *SessionStore) GetBool(key string) bool
- func (st *SessionStore) GetDate(key string) time.Time
- func (st *SessionStore) GetFloat(key string) float64
- func (st *SessionStore) GetInt(key string) int64
- func (st *SessionStore) GetString(key string) string
- func (st *SessionStore) Put(key string, value interface{}) error
- func (st *SessionStore) SessionID() string
- func (st *SessionStore) Set(key string, value interface{}) error
- func (st *SessionStore) TimeAccessed() time.Time
- func (st *SessionStore) TimeCreated() time.Time
Constants ¶
const LOG_PREF = "pg provider:"
const PROVIDER = "pg"
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 ¶
var EKeyNotFound = errors.New("key not found")
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) CloseProvider ¶
func (pder *Provider) CloseProvider()
CloseProvider closes all database connections.
func (*Provider) DestroyAllSessions ¶
func (*Provider) GetMaxIdleTime ¶
func (*Provider) GetMaxLifeTime ¶
func (*Provider) GetSessionIDLen ¶
func (*Provider) InitProvider ¶
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 (*Provider) SessionDestroy ¶
SessionDestroy destoys session by its ID.
func (*Provider) SessionInit ¶
SessionInit initializes session with given ID.
func (*Provider) SessionRead ¶
SessionRead reads session data from db to memory.
func (*Provider) SetMaxIdleTime ¶
func (*Provider) SetMaxLifeTime ¶
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.