OpenTopicURL opens a pubsub.Topic based on u.
(ctx context.Context, u *url.URL)
| 78 | |
| 79 | // OpenTopicURL opens a pubsub.Topic based on u. |
| 80 | func (o *URLOpener) OpenTopicURL(ctx context.Context, u *url.URL) (*pubsub.Topic, error) { |
| 81 | for param := range u.Query() { |
| 82 | return nil, fmt.Errorf("open topic %v: invalid query parameter %q", u, param) |
| 83 | } |
| 84 | topicName := path.Join(u.Host, u.Path) |
| 85 | o.mu.Lock() |
| 86 | defer o.mu.Unlock() |
| 87 | if o.topics == nil { |
| 88 | o.topics = map[string]*pubsub.Topic{} |
| 89 | } |
| 90 | t := o.topics[topicName] |
| 91 | if t == nil { |
| 92 | t = NewTopic() |
| 93 | o.topics[topicName] = t |
| 94 | } |
| 95 | return t, nil |
| 96 | } |
| 97 | |
| 98 | // OpenSubscriptionURL opens a pubsub.Subscription based on u. |
| 99 | func (o *URLOpener) OpenSubscriptionURL(ctx context.Context, u *url.URL) (*pubsub.Subscription, error) { |