persistence

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2023 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package persistence provides different persistence implementations. Part of this package is the database implementation and the session storage.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrDBConn is the error returned when the database connection fails.
	ErrDBConn = fmt.Errorf("error connecting to database")
)

Functions

func NewDB

func NewDB(cfg *PostgresDBCfg) (*pgxpool.Pool, error)

NewDB creates a new database connection pool.

Types

type Cfg

type Cfg struct {
	DB *PostgresDBCfg `toml:"db"`
}

Cfg is the configuration for the persistence package.

type PostgresDBCfg

type PostgresDBCfg struct {
	Host     string `toml:"host" env:"DB_HOST" validate:"required"`
	Port     string `toml:"port" env:"DB_PORT" validate:"required"`
	User     string `toml:"user" env:"DB_USER" validate:"required"`
	Pass     string `toml:"pass" env:"DB_PASS" validate:"required"`
	Name     string `toml:"name" env:"DB_NAME" validate:"required"`
	SSLMode  string `toml:"ssl_mode" env:"DB_SSL_MODE" validate:"required"`
	MaxConns string `toml:"max_conns" env:"DB_MAX_CONNS" validate:"required"`
}

PostgresDBCfg is the configuration for the Postgres database.

func (*PostgresDBCfg) String

func (cfg *PostgresDBCfg) String() string

String returns the string representation of the database configuration.

type SessionStorage

type SessionStorage interface {
	Create(data string) (string, error)  // Create returns the ID of the newly created session.
	Read(id string) (string, error)      // Read returns the data associated with the session ID.
	Update(id string, data string) error // Update updates the data associated with the session ID.
	Delete(id string) error              // Delete deletes the session by ID.
}

SessionStorage defines possible operations on a session storage while abstracting the underlying implementation.

Jump to

Keyboard shortcuts

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