rdsmysql

package
v0.43.0 Latest Latest
Warning

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

Go to latest
Published: May 15, 2019 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package rdsmysql provides connections to AWS RDS MySQL instances.

URLs

For mysql.Open, rdsmysql registers for the scheme "rdsmysql". The default URL opener will create a connection using the default credentials from the environment, as described in https://docs.aws.amazon.com/sdk-for-go/api/aws/session/. To customize the URL opener, or for more details on the URL format, see URLOpener.

See https://github.com/eliben/gocdkx/concepts/urls/ for background information.

Example
package main

import (
	"context"

	"github.com/eliben/gocdkx/mysql/rdsmysql"
)

func main() {
	ctx := context.Background()
	db, cleanup, err := rdsmysql.Open(ctx, new(rdsmysql.CertFetcher), &rdsmysql.Params{
		// Replace these with your actual settings.
		Endpoint: "example01.xyzzy.us-west-1.rds.amazonaws.com",
		User:     "myrole",
		Password: "swordfish",
		Database: "test",
	})
	if err != nil {
		panic(err)
	}
	defer cleanup()

	// Use database in your program.
	db.ExecContext(ctx, "CREATE TABLE foo (bar INT);")
}
Output:

Index

Examples

Constants

View Source
const Scheme = "rdsmysql"

Scheme is the URL scheme rdsmysql registers its URLOpener under on mysql.DefaultMux.

Variables

Set is a Wire provider set that provides a *sql.DB given *Params and an HTTP client.

Functions

func Open

func Open(ctx context.Context, provider CertPoolProvider, params *Params) (*sql.DB, func(), error)

Open opens an encrypted connection to an RDS MySQL database.

The second return value is a Wire cleanup function that calls Close on the database and ignores the error.

Types

type CertFetcher

type CertFetcher = rds.CertFetcher

CertFetcher pulls the RDS CA certificates from Amazon's servers. The zero value will fetch certificates using the default HTTP client.

type CertPoolProvider

type CertPoolProvider = rds.CertPoolProvider

A CertPoolProvider obtains a certificate pool that contains the RDS CA certificate.

type Params

type Params struct {
	// Endpoint is the host/port of the RDS database, like
	// "myinstance.borkxyzzy.us-west-1.rds.amazonaws.com:3306".
	// If no port is given, then 3306 is assumed.
	Endpoint string
	// User is the database user to connect as.
	User string
	// Password is the database user password to use.
	Password string
	// Database is the MySQL database name to connect to.
	Database string

	// TraceOpts contains options for OpenCensus.
	TraceOpts []ocsql.TraceOption
}

Params specifies how to connect to an RDS database.

type URLOpener

type URLOpener struct {
	// CertSource specifies how the opener will obtain authentication information.
	// CertSource must not be nil.
	CertSource rds.CertPoolProvider
	// TraceOpts contains options for OpenCensus.
	TraceOpts []ocsql.TraceOption
}

URLOpener opens RDS MySQL URLs like "rdsmysql://user:password@myinstance.borkxyzzy.us-west-1.rds.amazonaws.com:3306/mydb".

func (*URLOpener) OpenMySQLURL

func (uo *URLOpener) OpenMySQLURL(ctx context.Context, u *url.URL) (*sql.DB, error)

OpenMySQLURL opens a new RDS database connection wrapped with OpenCensus instrumentation.

Jump to

Keyboard shortcuts

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