awsmysql

package
v0.17.1 Latest Latest
Warning

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

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

Documentation

Overview

Package awsmysql provides connections to AWS RDS MySQL instances.

URLs

For mysql.Open, awsmysql registers for the scheme "awsmysql". 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/cornelk/go-cloud/concepts/urls/ for background information.

Example
package main

import (
	"context"
	"log"

	"github.com/cornelk/go-cloud/mysql"
	_ "github.com/cornelk/go-cloud/mysql/awsmysql"
)

func main() {
	// PRAGMA: This example is used on github.com/cornelk/go-cloud; PRAGMA comments adjust how it is shown and can be ignored.
	// PRAGMA: On github.com/cornelk/go-cloud, add a blank import: _ "github.com/cornelk/go-cloud/mysql/awsmysql"
	// PRAGMA: On github.com/cornelk/go-cloud, hide lines until the next blank line.
	ctx := context.Background()

	// Replace these with your actual settings.
	db, err := mysql.Open(ctx,
		"awsmysql://myrole:swordfish@example01.xyzzy.us-west-1.rds.amazonaws.com/testdb")
	if err != nil {
		log.Fatal(err)
	}
	defer db.Close()

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

Index

Examples

Constants

View Source
const Scheme = "awsmysql"

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

Variables

View Source
var Set = wire.NewSet(
	wire.Struct(new(URLOpener), "CertSource"),
	rds.CertFetcherSet,
)

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

Functions

This section is empty.

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 URLOpener

type URLOpener struct {
	// CertSource specifies how the opener will obtain the RDS Certificate
	// Authority. If nil, it will use the default *rds.CertFetcher.
	CertSource rds.CertPoolProvider
	// TraceOpts contains options for OpenCensus.
	TraceOpts []ocsql.TraceOption
}

URLOpener opens RDS MySQL URLs like "awsmysql://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