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

Method defaultConn

pubsub/gcppubsubv2/gcppubsub.go:134–164  ·  view source on GitHub ↗
(ctx context.Context)

Source from the content-addressed store, hash-verified

132}
133
134func (o *lazyCredsOpener) defaultConn(ctx context.Context) (*URLOpener, error) {
135 o.init.Do(func() {
136 var conn *grpc.ClientConn
137 var err error
138 if e := os.Getenv("PUBSUB_EMULATOR_HOST"); e != "" {
139 // Connect to the GCP pubsub emulator by overriding the default endpoint
140 // if the 'PUBSUB_EMULATOR_HOST' environment variable is set.
141 // Check https://cloud.google.com/pubsub/docs/emulator for more info.
142 endPoint = e
143 conn, err = dialEmulator(ctx, e)
144 if err != nil {
145 o.err = err
146 return
147 }
148 } else {
149 creds, err := gcp.DefaultCredentials(ctx)
150 if err != nil {
151 o.err = err
152 return
153 }
154
155 conn, _, err = Dial(ctx, creds.TokenSource)
156 if err != nil {
157 o.err = err
158 return
159 }
160 }
161 o.opener = &URLOpener{Conn: conn}
162 })
163 return o.opener, o.err
164}
165
166func (o *lazyCredsOpener) OpenTopicURL(ctx context.Context, u *url.URL) (*pubsub.Topic, error) {
167 opener, err := o.defaultConn(ctx)

Callers 2

OpenTopicURLMethod · 0.95
OpenSubscriptionURLMethod · 0.95

Calls 4

DefaultCredentialsFunction · 0.92
DoMethod · 0.80
dialEmulatorFunction · 0.70
DialFunction · 0.70

Tested by

no test coverage detected