Documentation
¶
Overview ¶
Package cloudmysql provides connections to managed MySQL Cloud SQL instances.
Example ¶
package main
import (
"context"
"github.com/google/go-cloud/gcp"
"github.com/google/go-cloud/gcp/cloudsql"
"github.com/google/go-cloud/mysql/cloudmysql"
"golang.org/x/oauth2"
"golang.org/x/oauth2/google"
)
func main() {
ctx := context.Background()
creds, err := google.FindDefaultCredentials(ctx, "https://www.googleapis.com/auth/cloud-platform")
if err != nil {
panic(err)
}
authClient := gcp.HTTPClient{Client: *oauth2.NewClient(ctx, creds.TokenSource)}
db, err := cloudmysql.Open(ctx, cloudsql.NewCertSource(&authClient), &cloudmysql.Params{
// Replace these with your actual settings.
ProjectID: "example-project",
Region: "us-central1",
Instance: "my-instance01",
User: "myrole",
Database: "test",
})
if err != nil {
panic(err)
}
// Use database in your program.
db.Exec("CREATE TABLE foo (bar INT);")
}
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var CertSourceSet = cloudsql.CertSourceSet
CertSourceSet is a Wire provider set that binds a Cloud SQL proxy certificate source from an GCP-authenticated HTTP client.
Deprecated: Use cloudsql.CertSourceSet.
Functions ¶
func NewCertSource
deprecated
func NewCertSource(c *gcp.HTTPClient) *certs.RemoteCertSource
NewCertSource creates a local certificate source that uses the given HTTP client. The client is assumed to make authenticated requests.
Deprecated: Use cloudsql.NewCertSource.
Types ¶
type Params ¶
type Params struct {
// ProjectID specifies the GCP project associated with the
// CloudSQL instance.
ProjectID string
// Region is the GCP region containing the CloudSQL instance.
Region string
// Instance is the CloudSQL instance name. See
// https://cloud.google.com/sql/docs/mysql/create-instance
// for background.
Instance string
// User is the username used to connect to the database.
User string
// Password is the password used to connect to the database.
// It may be empty, see https://cloud.google.com/sql/docs/sql-proxy#user
Password string
// Database is the name of the database to connect to.
Database string
// TraceOpts contains options for OpenCensus.
TraceOpts []ocsql.TraceOption
}
Params specifies how to connect to a Cloud SQL database.
Click to show internal directories.
Click to hide internal directories.