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

Method OpenSubscriptionURL

pubsub/gcppubsub/gcppubsub.go:241–280  ·  view source on GitHub ↗

OpenSubscriptionURL opens a pubsub.Subscription based on u.

(ctx context.Context, u *url.URL)

Source from the content-addressed store, hash-verified

239
240// OpenSubscriptionURL opens a pubsub.Subscription based on u.
241func (o *URLOpener) OpenSubscriptionURL(ctx context.Context, u *url.URL) (*pubsub.Subscription, error) {
242 // Set subscription options to use defaults
243 opts := o.SubscriptionOptions
244
245 for param, value := range u.Query() {
246 switch param {
247 case "max_recv_batch_size":
248 maxBatchSize, err := queryParameterInt(value)
249 if err != nil {
250 return nil, fmt.Errorf("open subscription %v: invalid query parameter %q: %v", u, param, err)
251 }
252
253 if maxBatchSize <= 0 || maxBatchSize > 1000 {
254 return nil, fmt.Errorf("open subscription %v: invalid query parameter %q: must be between 1 and 1000", u, param)
255 }
256
257 opts.MaxBatchSize = maxBatchSize
258 case "nacklazy":
259 var err error
260 nackLazy, err := queryParameterBool(value)
261 if err != nil {
262 return nil, fmt.Errorf("open subscription %v: invalid query parameter %q: %v", u, param, err)
263 }
264 opts.NackLazy = nackLazy
265 default:
266 return nil, fmt.Errorf("open subscription %v: invalid query parameter %q", u, param)
267 }
268 }
269 sc, err := SubscriberClient(ctx, o.Conn)
270 if err != nil {
271 return nil, err
272 }
273 subPath := path.Join(u.Host, u.Path)
274 if subscriptionPathRE.MatchString(subPath) {
275 return OpenSubscriptionByPath(sc, subPath, &opts)
276 }
277 // Shortened form?
278 subName := strings.TrimPrefix(u.Path, "/")
279 return OpenSubscription(sc, gcp.ProjectID(u.Host), subName, &opts), nil
280}
281
282type topic struct {
283 path string

Callers

nothing calls this directly

Calls 7

ProjectIDTypeAlias · 0.92
queryParameterBoolFunction · 0.85
SubscriberClientFunction · 0.85
QueryMethod · 0.80
queryParameterIntFunction · 0.70
OpenSubscriptionByPathFunction · 0.70
OpenSubscriptionFunction · 0.70

Tested by

no test coverage detected