Documentation
¶
Index ¶
- Variables
- func SetDriverRegistry(registry DriverRegistry)
- type CacheDriver
- type Connections
- func (d *Connections) Close() (errs []error)
- func (d *Connections) DB() *sql.DB
- func (d *Connections) DBRead() (*sql.DB, error)
- func (d *Connections) Ping(ctx context.Context) error
- func (d *Connections) PingRedis(ctx context.Context) error
- func (d *Connections) ReadDB() (*sql.DB, error)
- func (d *Connections) SearchHealth(ctx context.Context) map[string]error
- type DBManager
- type DatabaseDriver
- type DriverRegistry
- type LoadBalancer
- type MessageDriver
- type RandomBalancer
- type RoundRobinBalancer
- type SearchDriver
- type WeightBalancer
Constants ¶
This section is empty.
Variables ¶
var ( ErrNoAvailableSlaves = errors.New("no available read replica databases") ErrInvalidStrategy = errors.New("invalid load balance strategy") )
Functions ¶
func SetDriverRegistry ¶ added in v0.2.0
func SetDriverRegistry(registry DriverRegistry)
SetDriverRegistry is called by the data package to inject the registry.
Types ¶
type CacheDriver ¶ added in v0.2.0
type Connections ¶
type Connections struct {
DBM *DBManager
RC any
MS any
ES any
OS any
MGM any
Neo any
RMQ any
KFK any
// contains filtered or unexported fields
}
func (*Connections) Close ¶
func (d *Connections) Close() (errs []error)
func (*Connections) DB ¶
func (d *Connections) DB() *sql.DB
func (*Connections) PingRedis ¶ added in v0.2.5
func (d *Connections) PingRedis(ctx context.Context) error
PingRedis checks the configured Redis client.
func (*Connections) SearchHealth ¶ added in v0.2.5
func (d *Connections) SearchHealth(ctx context.Context) map[string]error
SearchHealth checks all configured search clients and returns per-engine errors. An empty result means no search engine is configured.
type DBManager ¶
type DBManager struct {
// contains filtered or unexported fields
}
DBManager manages database connections for read-write splitting
func NewDBManager ¶
NewDBManager creates a new database manager with read-write splitting
func (*DBManager) Slave ¶
Slave returns a slave database connection based on the load balancing strategy
func (*DBManager) SlaveContext ¶ added in v0.2.5
SlaveContext returns a read database connection. If no read replicas are configured, the primary connection is returned. If replicas are configured but unavailable, an error is returned instead of silently routing reads to primary.
type DatabaseDriver ¶ added in v0.2.0
type DatabaseDriver interface {
Name() string
Connect(ctx context.Context, cfg any) (any, error)
Close(conn any) error
Ping(ctx context.Context, conn any) error
}
DatabaseDriver mirrors the interface from data package to avoid import cycle.
type DriverRegistry ¶ added in v0.2.0
type DriverRegistry interface {
GetDatabaseDriver(name string) (DatabaseDriver, error)
GetCacheDriver(name string) (CacheDriver, error)
GetSearchDriver(name string) (SearchDriver, error)
GetMessageDriver(name string) (MessageDriver, error)
}
DriverRegistry defines the driver lookups needed from the parent data package.
type LoadBalancer ¶
LoadBalancer LoadBalancer interface
type MessageDriver ¶ added in v0.2.0
type RoundRobinBalancer ¶
type RoundRobinBalancer struct {
// contains filtered or unexported fields
}
RoundRobinBalancer Implement polling strategy
func NewRoundRobinBalancer ¶
func NewRoundRobinBalancer() *RoundRobinBalancer
NewRoundRobinBalancer Create new RoundRobinBalancer
type SearchDriver ¶ added in v0.2.0
type WeightBalancer ¶
type WeightBalancer struct {
// contains filtered or unexported fields
}
WeightBalancer Implement weight strategy
func NewWeightBalancer ¶
func NewWeightBalancer(slaves []*config.DBNode) *WeightBalancer