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

Method OpenTopicURL

pubsub/gcppubsubv2/gcppubsub.go:209–240  ·  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

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

Callers

nothing calls this directly

Calls 6

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

Tested by

no test coverage detected