MCPcopy Create free account
hub / github.com/google/go-cloud / OpenPostgresURL

Method OpenPostgresURL

postgres/gcppostgres/gcppostgres.go:67–86  ·  view source on GitHub ↗
(ctx context.Context, u *url.URL)

Source from the content-addressed store, hash-verified

65}
66
67func (o *lazyCredsOpener) OpenPostgresURL(ctx context.Context, u *url.URL) (*sql.DB, error) {
68 o.init.Do(func() {
69 creds, err := gcp.DefaultCredentials(ctx)
70 if err != nil {
71 o.err = err
72 return
73 }
74 client, err := gcp.NewHTTPClient(gcp.DefaultTransport(), creds.TokenSource)
75 if err != nil {
76 o.err = err
77 return
78 }
79 certSource := cloudsql.NewCertSourceWithIAM(client, creds.TokenSource)
80 o.opener = &URLOpener{CertSource: certSource}
81 })
82 if o.err != nil {
83 return nil, fmt.Errorf("gcppostgres open %v: %v", u, o.err)
84 }
85 return o.opener.OpenPostgresURL(ctx, u)
86}
87
88// URLOpener opens GCP PostgreSQL URLs
89// like "gcppostgres://user:password@myproject/us-central1/instanceId/mydb".

Callers

nothing calls this directly

Calls 6

DefaultCredentialsFunction · 0.92
NewHTTPClientFunction · 0.92
DefaultTransportFunction · 0.92
NewCertSourceWithIAMFunction · 0.92
DoMethod · 0.80
OpenPostgresURLMethod · 0.65

Tested by

no test coverage detected