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

Method defaultConn

pubsub/gcppubsub/gcppubsub.go:131–161  ·  view source on GitHub ↗
(ctx context.Context)

Source from the content-addressed store, hash-verified

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