rdsmysql

package
v0.0.0-...-1538fac Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2024 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package rdsmysql provides connections to AWS RDS MySQL instances.

Example
package main

import (
	"context"

	"github.com/Lioric/go-cloud/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

This section is empty.

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 struct {
	// Client is the HTTP client used to make requests. If nil, then
	// http.DefaultClient is used.
	Client *http.Client
}

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

func (*CertFetcher) Fetch

func (cf *CertFetcher) Fetch(ctx context.Context) ([]*x509.Certificate, error)

Fetch fetches the RDS CA certificates. It is safe to call from multiple goroutines.

func (*CertFetcher) RDSCertPool

func (cf *CertFetcher) RDSCertPool(ctx context.Context) (*x509.CertPool, error)

RDSCertPool fetches the RDS CA certificates and places them into a pool. It is safe to call from multiple goroutines.

type CertPoolProvider

type CertPoolProvider interface {
	RDSCertPool(context.Context) (*x509.CertPool, error)
}

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
}

Params specifies how to connect to an RDS database.

Jump to

Keyboard shortcuts

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