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

Method OpenTopicURL

pubsub/gcppubsub/gcppubsub.go:207–238  ·  view source on GitHub ↗

OpenTopicURL opens a pubsub.Topic based on u.

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

Source from the content-addressed store, hash-verified

205
206// OpenTopicURL opens a pubsub.Topic based on u.
207func (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.
241func (o *URLOpener) OpenSubscriptionURL(ctx context.Context, u *url.URL) (*pubsub.Subscription, error) {

Callers

nothing calls this directly

Calls 6

ProjectIDTypeAlias · 0.92
PublisherClientFunction · 0.85
QueryMethod · 0.80
queryParameterIntFunction · 0.70
OpenTopicByPathFunction · 0.70
OpenTopicFunction · 0.70

Tested by

no test coverage detected