OpenSubscriptionURL opens a pubsub.Subscription based on u.
(ctx context.Context, u *url.URL)
| 239 | |
| 240 | // OpenSubscriptionURL opens a pubsub.Subscription based on u. |
| 241 | func (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 | |
| 282 | type topic struct { |
| 283 | path string |
nothing calls this directly
no test coverage detected