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/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, cloudmysql.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 = wire.NewSet( NewCertSource, wire.Bind((*proxy.CertSource)(nil), (*certs.RemoteCertSource)(nil)))
CertSourceSet is a Wire provider set that binds a Cloud SQL proxy certificate source from an GCP-authenticated HTTP client.
Functions ¶
func NewCertSource ¶
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.
Types ¶
Click to show internal directories.
Click to hide internal directories.