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