gocloud.dev: gocloud.dev/postgres/gcppostgres Index | Examples | Files

package gcppostgres

import "gocloud.dev/postgres/gcppostgres"

Package gcppostgres provides connections to managed PostgreSQL Cloud SQL instances. See https://cloud.google.com/sql/docs/postgres/ for more information.

URLs

For postgres.Open, gcppostgres registers for the scheme "gcppostgres". 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:

// This example is used in https://gocloud.dev/howto/sql/#gcp

// import _ "gocloud.dev/postgres/gcppostgres"

// Variables set up elsewhere:
ctx := context.Background()

db, err := postgres.Open(ctx,
    "gcppostgres://myrole@example-project/us-central1/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

gcppostgres.go

Constants

const Scheme = "gcppostgres"

Scheme is the URL scheme gcppostgres registers its URLOpener under on postgres.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 GCP PostgreSQL URLs like "gcppostgres://user:password@myproject/us-central1/instanceId/mydb".

func (*URLOpener) OpenPostgresURL Uses

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

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

Package gcppostgres imports 16 packages (graph). Updated 2019-07-04. Refresh now. Tools for package owners.