mysql

package
v0.0.0-...-d6b3ade Latest Latest
Warning

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

Go to latest
Published: Jan 3, 2024 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Open

func Open(c Config) (*sqlx.DB, error)

Open uses the provided Config to connect to a MySQL database. If the connection is opened successfully, Open will also try to ping the connection to validate it further.

func Try

func Try(c Config, dur, interval time.Duration) (*sqlx.DB, error)

Try wraps Open in a retry loop, retrying failed connections every interval until dur is elapsed.

Types

type Config

type Config struct {
	User       string `envconfig:"USER" required:"true" default:"root"`
	Password   string `envconfig:"PASSWD"`
	Host       string `envconfig:"HOST" required:"true" default:"localhost"`
	Port       int    `envconfig:"PORT" required:"true" default:"3306"`
	DB         string `envconfig:"DB" required:"true"`
	TLS        string `envconfig:"TLS"`
	IAMAuth    bool   `envconfig:"IAM_AUTH"`
	CACertPath string `envconfig:"CA_CERT_PATH"`
}

type DBMux

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

func NewDBMux

func NewDBMux(db *sqlx.DB) *DBMux

func (*DBMux) DB

func (m *DBMux) DB() *sqlx.DB

func (*DBMux) Refresh

func (m *DBMux) Refresh(log logrus.FieldLogger, c Config, dur time.Duration)

Refresh periodically refreshes the passed DB connection, if the connection is using IAM authentication. Credentials generated this way last for 15 minutes, per AWS's documentation:

https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/UsingWithRDS.IAMDBAuth.html

This function should be run as a goroutine, i.e.:

db, _ := mysql.Open(cfg) go mysql.Refresh(log, cfg, 10 * time.Minute, db)

Jump to

Keyboard shortcuts

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