Documentation
¶
Index ¶
- func ReplaceGlobals(databases Databases) func()
- func StartHealthMonitoring(name string, interval time.Duration, checker HealthCheckable, recover func()) func()
- type Databases
- type HealthCheckable
- type HealthMonitor
- type HealthTarget
- type PostgresDB
- type RedisDB
- type Sql
- type SqlCredentials
- type SqlDatabase
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ReplaceGlobals ¶
func ReplaceGlobals(databases Databases) func()
ReplaceGlobals replaces the global Databases struct with the provided one
func StartHealthMonitoring ¶
func StartHealthMonitoring(name string, interval time.Duration, checker HealthCheckable, recover func()) func()
StartHealthMonitoring is a convenience function to create a manager, add a target, and start monitoring
Types ¶
type Databases ¶
type Databases struct {
// contains filtered or unexported fields
}
Databases holds all the database connections
func (*Databases) CloseAll ¶
func (db *Databases) CloseAll()
CloseAll closes all database connections
func (*Databases) Postgres ¶
func (db *Databases) Postgres() PostgresDB
Postgres returns the postgres database connection
func (*Databases) SetPostgres ¶
func (db *Databases) SetPostgres(postgres PostgresDB)
SetPostgres sets the postgres database connection while preserving other connections
type HealthCheckable ¶
type HealthCheckable interface {
IsHealthy() bool
}
HealthCheckable represents any database connection that can be health-checked
type HealthMonitor ¶
type HealthMonitor struct {
// contains filtered or unexported fields
}
HealthMonitor manages multiple health targets with a single goroutine
func NewHealthMonitor ¶
func NewHealthMonitor(interval time.Duration) *HealthMonitor
NewHealthMonitor creates a new health check manager with the given interval
func (*HealthMonitor) AddTarget ¶
func (m *HealthMonitor) AddTarget(name string, checker HealthCheckable, recover func())
AddTarget registers a new health target with the monitor
func (*HealthMonitor) Start ¶
func (m *HealthMonitor) Start() func()
Start begins the health check monitoring for all registered checkers
type HealthTarget ¶
type HealthTarget struct { Name string Checker HealthCheckable Recover func() }
HealthTarget represents a registered health target with its settings
type PostgresDB ¶
func NewPostgresDB ¶
func NewPostgresDB(db SqlDatabase) PostgresDB
NewPostgresDB create a new Postgres DB.
func (PostgresDB) IsHealthy ¶
func (p PostgresDB) IsHealthy() bool
IsHealthy checks if the database connection is healthy by running a simple query.
type Sql ¶
type Sql struct {
SqlCredentials
}
Sql is a struct that holds the credentials for a SQL database.
type SqlCredentials ¶
type SqlCredentials struct { Host string `json:"url,omitempty"` Port string `json:"port,omitempty"` User string `json:"user,omitempty"` Password string `json:"password,omitempty"` DbName string `json:"dbname,omitempty"` }
SqlCredentials holds the credentials for a SQL database.
type SqlDatabase ¶
SqlDatabase is an interface for a SQL database.
func NewSqlDatabase ¶
func NewSqlDatabase(credentials SqlCredentials) SqlDatabase
NewSqlDatabase creates a new SQL database.