bereg

package
v0.0.0-...-444cd0b Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2025 License: MIT Imports: 12 Imported by: 0

README

                                  Таблица "public.sessions"
   Столбец   |           Тип            | Правило сортировки | Допустимость NULL | По умолчанию 
-------------+--------------------------+--------------------+-------------------+--------------
 id          | character(128)           |                    | not null          | 
 set_time    | timestamp with time zone |                    |                   | now()
 data        | text                     |                    |                   | 
 session_key | character(128)           |                    |                   | 
 pub_key     | character varying(15)    |                    |                   | 
 data_enc    | bytea                    |                    |                   | 
 create_time | timestamp with time zone |                    |                   | now()
Индексы:
    "sessions_pub_key_index" btree (pub_key)
    "sessions_set_time_idx" btree (set_time)
Триггеры:
    sessions_trigger_after AFTER DELETE ON sessions FOR EACH ROW EXECUTE FUNCTION sessions_process()

SELECT sess_enc_write('%s','%s','%s','%s',%d)
FUNCTION sess_enc_write(
    in_id character varying,
    in_data_enc text,
    in_key text,
    in_remote_ip character varying)
  RETURNS void AS



SELECT sess_enc_read('%s','%s')
sess_enc_read(in_id character varying,in_key text)

SELECT sess_gc('%d seconds'::interval)

Documentation

Overview

Package bereg contains postgresql session provider based on jackc connection to PG and pgp_session. 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 php_session_decorer 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

This section is empty.

Variables

View Source
var (
	ErrKeyNotFound  = errors.New("key not found")
	ErrValMustBePtr = errors.New("value must be of type ptr")
	ErrKeyLen       = errors.New("session key length exceeded max value")
)

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 (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 []any) 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 any) 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 any) error

func (*SessionStore) SessionID

func (st *SessionStore) SessionID() string

SessionID returns session unique ID.

func (*SessionStore) Set

func (st *SessionStore) Set(key string, value any) 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