Documentation ¶
Index ¶
- Constants
- Variables
- func MysqlFormatter(username, password, host string, port int, db string, opts map[string]string) string
- func PgFormatter(username, password, host string, port int, db string, opts map[string]string) string
- func PgKVFormatter(username, password, host string, port int, db string, opts map[string]string) string
- func Register(name string, f factory) error
- type AuthError
- type Config
- type Connector
- type Credentials
- type Driver
- type Formatter
- type Store
Constants ¶
const ( MysqlErrorText = "access denied for user" PgErrorText = "password authentication failed for user" )
Variables ¶
var ( ErrConfigRequired = errors.New("config is required") ErrNoNilCredentials = errors.New("store cannot return nil credentials") ErrMissingUsername = errors.New("missing username") ErrMissingPassword = errors.New("missing password") )
var MySQLAuthError = errorTester(MysqlErrorText) //nolint:gochecknoglobals
MySQLAuthError tests whether an error from MySQL is an authentication failure.
var PostgreSQLAuthError = errorTester(PgErrorText) //nolint:gochecknoglobals
PostgreSQLAuthError tests whether an error from PostgreSQL is an authentication failure.
Functions ¶
func MysqlFormatter ¶
func MysqlFormatter(username, password, host string, port int, db string, opts map[string]string) string
MysqlFormatter formats a connection string for the go-sql-driver/mysql lib NOTE: Currently only supports TCP connections.
func PgFormatter ¶
func PgFormatter(username, password, host string, port int, db string, opts map[string]string) string
PgFormatter formats a connection URI for the pq and pgx lib.
func PgKVFormatter ¶
func PgKVFormatter(username, password, host string, port int, db string, opts map[string]string) string
PgKVFormatter formats a connection string in the K/V format.
func Register ¶
Register registers a DB driver Note: Register behaves similarly to database/sql.Register except that it doesn't panic on duplicate registrations, it just ignores them and continues. The reason we Register drivers separately from database/sql is because
a) most DB drivers already call database/sql.Register in an init() func b) we need to carry a lot more information along with the driver to ensure our connector logic works correctly.
Types ¶
type AuthError ¶
AuthError is a func to evaluate the DB-specific error string that indicates an authentication error.
type Config ¶
type Config struct { Host string Port int DB string Opts map[string]string Retries int Formatter Formatter }
Config is a struct that holds non-credential database configuration.
type Connector ¶
type Connector struct {
// contains filtered or unexported fields
}
Connector represents a driver in a fixed configuration.
func NewConnector ¶
NewConnector creates a new connector from a store.
type Credentials ¶
Credentials represents an abstraction over a username and password.
type Driver ¶
Driver carries information along with a database/sql/driver required for creating a Connector
type Formatter ¶
type Formatter func(username string, password string, host string, port int, db string, opts map[string]string) string
Formatter takes connection string components and assembles them into an implementation-specific conn string/DSN.
type Store ¶
type Store interface { Get(ctx context.Context) (Credentials, error) Refresh(ctx context.Context) (Credentials, error) }
Store represents a mechanism for retrieving Credentials.