dbreaker

package module
v0.0.0-...-1b2eedb Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2020 License: MIT Imports: 4 Imported by: 1

README

dbreaker

Simple circuit breaker for sql.DB connections

Documentation

Overview

Package dbreaker provides a simple "circuit breaker" wrapper for sql.DB connections

It wraps the original driver with a new driver that exposes a Disable function that can toggle access to the database. This allows for stopping db operations for maintence purposes without modifying application code

Index

Constants

This section is empty.

Variables

View Source
var ErrContext = fmt.Errorf("context operations are not supported")

ErrContext is returned when context operations are not supported

View Source
var ErrDown = fmt.Errorf("database is down")

ErrDown is returned when circuit breaker is enabled

Functions

This section is empty.

Types

type Breaker

type Breaker struct {
	// contains filtered or unexported fields
}

Breaker is an sql.Driver that can block access to the database

func (*Breaker) Disable

func (w *Breaker) Disable(off bool)

Disable allows changing if dribver is enabled

func (*Breaker) Open

func (w *Breaker) Open(name string) (driver.Conn, error)

Open satisfies the sql.Driver interface

type Conn

type Conn struct {
	// contains filtered or unexported fields
}

Conn implements the sql.Driver.Conn interface

func (*Conn) Begin deprecated

func (c *Conn) Begin() (driver.Tx, error)

Begin starts and returns a new transaction.

Deprecated: Drivers should implement ConnBeginTx instead (or additionally).

func (*Conn) BeginTx

func (c *Conn) BeginTx(ctx context.Context, opts driver.TxOptions) (driver.Tx, error)

BeginTx starts and returns a new transaction using a context.

func (*Conn) Close

func (c *Conn) Close() error

Close invalidates and potentially stops any current prepared statements and transactions, marking this connection as no longer in use.

Because the sql package maintains a free pool of connections and only calls Close when there's a surplus of idle connections, it shouldn't be necessary for drivers to do their own connection caching.

func (*Conn) Prepare

func (c *Conn) Prepare(query string) (driver.Stmt, error)

Prepare satisfies the sql.driver.Conn interface

type Downer

type Downer interface {
	driver.Driver
	Disable(bool)
}

Downer is an sql driver that can be disabled

func NewDriver

func NewDriver(name, native string) (Downer, error)

NewDriver registers and returns a driver wrapper that can control access to the inner driver

Jump to

Keyboard shortcuts

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