repositories

package
v0.0.0-...-a4aa88a Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2024 License: GPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EnvDbConnStr = "DB_CONN_STR"
	EnvRedisHost = "REDIS_HOST"
)

Variables

This section is empty.

Functions

func GenerateConnectionStr

func GenerateConnectionStr(v *viper.Viper, vs *vault.Secrets) string

Types

type Database

type Database struct {
	*sqlx.DB
	*sync.RWMutex
}

func ConnectDB

func ConnectDB(ctx context.Context, v *VaultDB) (*Database, error)

ConnectDB connects to the database

func NewDatabase

func NewDatabase(db *sqlx.DB) *Database

NewDatabase establishes a database connection with the given Vault credentials

func (*Database) Close

func (d *Database) Close() error

func (*Database) PingContext

func (d *Database) PingContext(ctx context.Context) error

func (*Database) Reconnect

func (d *Database) Reconnect(ctx context.Context, db *sqlx.DB) error

Reconnect will be called periodically to refresh the database connection since the dynamic credentials expire after some time, it will:

  1. construct a connection string using the given credentials
  2. establish a database connection
  3. close & replace the existing connection with the new one behind a mutex

type VaultDB

type VaultDB struct {
	Client         vault.Client
	Vip            *viper.Viper
	Enabled        bool
	CurrentSecrets *vault.Secrets
}

Jump to

Keyboard shortcuts

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