OpenTopicURL opens a pubsub.Topic based on u.
(ctx context.Context, u *url.URL)
| 205 | |
| 206 | // OpenTopicURL opens a pubsub.Topic based on u. |
| 207 | func (o *URLOpener) OpenTopicURL(ctx context.Context, u *url.URL) (*pubsub.Topic, error) { |
| 208 | opts := o.TopicOptions |
| 209 | |
| 210 | for param, value := range u.Query() { |
| 211 | switch param { |
| 212 | case "max_send_batch_size": |
| 213 | maxBatchSize, err := queryParameterInt(value) |
| 214 | if err != nil { |
| 215 | return nil, fmt.Errorf("open topic %v: invalid query parameter %q: %v", u, param, err) |
| 216 | } |
| 217 | |
| 218 | if maxBatchSize <= 0 || maxBatchSize > 1000 { |
| 219 | return nil, fmt.Errorf("open topic %v: invalid query parameter %q: must be between 1 and 1000", u, param) |
| 220 | } |
| 221 | |
| 222 | opts.BatcherOptions.MaxBatchSize = maxBatchSize |
| 223 | default: |
| 224 | return nil, fmt.Errorf("open topic %v: invalid query parameter %q", u, param) |
| 225 | } |
| 226 | } |
| 227 | pc, err := PublisherClient(ctx, o.Conn) |
| 228 | if err != nil { |
| 229 | return nil, err |
| 230 | } |
| 231 | topicPath := path.Join(u.Host, u.Path) |
| 232 | if topicPathRE.MatchString(topicPath) { |
| 233 | return OpenTopicByPath(pc, topicPath, &opts) |
| 234 | } |
| 235 | // Shortened form? |
| 236 | topicName := strings.TrimPrefix(u.Path, "/") |
| 237 | return OpenTopic(pc, gcp.ProjectID(u.Host), topicName, &opts), nil |
| 238 | } |
| 239 | |
| 240 | // OpenSubscriptionURL opens a pubsub.Subscription based on u. |
| 241 | func (o *URLOpener) OpenSubscriptionURL(ctx context.Context, u *url.URL) (*pubsub.Subscription, error) { |
nothing calls this directly
no test coverage detected