gocloud.dev: gocloud.dev/mysql/gcpmysql Index | Examples | Files

package gcpmysql

import "gocloud.dev/mysql/gcpmysql"

Package gcpmysql provides connections to managed MySQL Cloud SQL instances. See https://cloud.google.com/sql/docs/mysql/ for more information.

URLs

For mysql.Open, gcpmysql registers for the scheme "gcpmysql". The default URL opener will create a connection using the default credentials from the environment, as described in https://cloud.google.com/docs/authentication/production. To customize the URL opener, or for more details on the URL format, see URLOpener.

See https://gocloud.dev/concepts/urls/ for background information.

Code:

// PRAGMA: This example is used on gocloud.dev; PRAGMA comments adjust how it is shown and can be ignored.
// PRAGMA: On gocloud.dev, add a blank import: _ "gocloud.dev/mysql/gcpmysql"
// PRAGMA: On gocloud.dev, hide lines until the next blank line.
ctx := context.Background()

// Replace this with your actual settings.
db, err := mysql.Open(ctx,
    "gcpmysql://user:password@example-project/region/my-instance01/testdb")
if err != nil {
    log.Fatal(err)
}
defer db.Close()

// Use database in your program.
db.Exec("CREATE TABLE foo (bar INT);")

Index

Examples

Package Files

gcpmysql.go

Constants

const Scheme = "gcpmysql"

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

type URLOpener Uses

type URLOpener struct {
    // CertSource specifies how the opener will obtain authentication information.
    // CertSource must not be nil.
    CertSource proxy.CertSource

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

URLOpener opens Cloud MySQL URLs like "gcpmysql://user:password@project/region/instance/dbname".

func (*URLOpener) OpenMySQLURL Uses

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

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

Package gcpmysql imports 13 packages (graph) and is imported by 2 packages. Updated 2019-08-07. Refresh now. Tools for package owners.