Debian Codegraph @

eventarc/publishing/apiv1/publisher_client.go

raw symbols SCIP
1 // Copyright 2025 Google LLC
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 // Code generated by protoc-gen-go_gapic. DO NOT EDIT.
16
17 package publishing
18
19 import (
20 "bytes"
21 "context"
22 "fmt"
23 "log/slog"
24 "math"
25 "net/http"
26 "net/url"
27 "time"
28
29 publishingpb "cloud.google.com/go/eventarc/publishing/apiv1/publishingpb"
30 gax "github.com/googleapis/gax-go/v2"
31 "google.golang.org/api/option"
32 "google.golang.org/api/option/internaloption"
33 gtransport "google.golang.org/api/transport/grpc"
34 httptransport "google.golang.org/api/transport/http"
35 "google.golang.org/grpc"
36 "google.golang.org/protobuf/encoding/protojson"
37 )
38
39 var newPublisherClientHook clientHook
40
41 // PublisherCallOptions contains the retry settings for each method of PublisherClient.
42 type PublisherCallOptions struct {
43 PublishChannelConnectionEvents []gax.CallOption
44 PublishEvents []gax.CallOption
45 Publish []gax.CallOption
46 }
47
48 func defaultPublisherGRPCClientOptions() []option.ClientOption {
49 return []option.ClientOption{
50 internaloption.WithDefaultEndpoint("eventarcpublishing.googleapis.com:443"),
51 internaloption.WithDefaultEndpointTemplate("eventarcpublishing.UNIVERSE_DOMAIN:443"),
52 internaloption.WithDefaultMTLSEndpoint("eventarcpublishing.mtls.googleapis.com:443"),
53 internaloption.WithDefaultUniverseDomain("googleapis.com"),
54 internaloption.WithDefaultAudience("https://eventarcpublishing.googleapis.com/"),
55 internaloption.WithDefaultScopes(DefaultAuthScopes()...),
56 internaloption.EnableJwtWithScope(),
57 internaloption.EnableNewAuthLibrary(),
58 option.WithGRPCDialOption(grpc.WithDefaultCallOptions(
59 grpc.MaxCallRecvMsgSize(math.MaxInt32))),
60 }
61 }
62
63 func defaultPublisherCallOptions() *PublisherCallOptions {
64 return &PublisherCallOptions{
65 PublishChannelConnectionEvents: []gax.CallOption{
66 gax.WithTimeout(60000 * time.Millisecond),
67 },
68 PublishEvents: []gax.CallOption{},
69 Publish: []gax.CallOption{
70 gax.WithTimeout(60000 * time.Millisecond),
71 },
72 }
73 }
74
75 func defaultPublisherRESTCallOptions() *PublisherCallOptions {
76 return &PublisherCallOptions{
77 PublishChannelConnectionEvents: []gax.CallOption{
78 gax.WithTimeout(60000 * time.Millisecond),
79 },
80 PublishEvents: []gax.CallOption{},
81 Publish: []gax.CallOption{
82 gax.WithTimeout(60000 * time.Millisecond),
83 },
84 }
85 }
86
87 // internalPublisherClient is an interface that defines the methods available from Eventarc Publishing API.
88 type internalPublisherClient interface {
89 Close() error
90 setGoogleClientInfo(...string)
91 Connection() *grpc.ClientConn
92 PublishChannelConnectionEvents(context.Context, *publishingpb.PublishChannelConnectionEventsRequest, ...gax.CallOption) (*publishingpb.PublishChannelConnectionEventsResponse, error)
93 PublishEvents(context.Context, *publishingpb.PublishEventsRequest, ...gax.CallOption) (*publishingpb.PublishEventsResponse, error)
94 Publish(context.Context, *publishingpb.PublishRequest, ...gax.CallOption) (*publishingpb.PublishResponse, error)
95 }
96
97 // PublisherClient is a client for interacting with Eventarc Publishing API.
98 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
99 //
100 // Eventarc processes events generated by an event provider and delivers them to
101 // a subscriber.
102 //
103 // An event provider is a software-as-a-service (SaaS) system or
104 // product that can generate and deliver events through Eventarc.
105 //
106 // A third-party event provider is an event provider from outside of Google.
107 //
108 // A partner is a third-party event provider that is integrated with Eventarc.
109 //
110 // A subscriber is a Google Cloud customer interested in receiving events.
111 //
112 // Channel is a first-class Eventarc resource that is created and managed
113 // by the subscriber in their Google Cloud project. A Channel represents a
114 // subscriber’s intent to receive events from an event provider. A Channel is
115 // associated with exactly one event provider.
116 //
117 // ChannelConnection is a first-class Eventarc resource that
118 // is created and managed by the partner in their Google Cloud project. A
119 // ChannelConnection represents a connection between a partner and a
120 // subscriber’s Channel. A ChannelConnection has a one-to-one mapping with a
121 // Channel.
122 //
123 // Bus is a first-class Eventarc resource that is created and managed in a
124 // Google Cloud project. A Bus provides a discoverable endpoint for events and
125 // is a router that receives all events published by event providers and
126 // delivers them to zero or more subscribers.
127 //
128 // Publisher allows an event provider to publish events to Eventarc.
129 type PublisherClient struct {
130 // The internal transport-dependent client.
131 internalClient internalPublisherClient
132
133 // The call options for this service.
134 CallOptions *PublisherCallOptions
135 }
136
137 // Wrapper methods routed to the internal client.
138
139 // Close closes the connection to the API service. The user should invoke this when
140 // the client is no longer required.
141 func (c *PublisherClient) Close() error {
142 return c.internalClient.Close()
143 }
144
145 // setGoogleClientInfo sets the name and version of the application in
146 // the `x-goog-api-client` header passed on each request. Intended for
147 // use by Google-written clients.
148 func (c *PublisherClient) setGoogleClientInfo(keyval ...string) {
149 c.internalClient.setGoogleClientInfo(keyval...)
150 }
151
152 // Connection returns a connection to the API service.
153 //
154 // Deprecated: Connections are now pooled so this method does not always
155 // return the same resource.
156 func (c *PublisherClient) Connection() *grpc.ClientConn {
157 return c.internalClient.Connection()
158 }
159
160 // PublishChannelConnectionEvents publish events to a ChannelConnection in a partner’s project.
161 func (c *PublisherClient) PublishChannelConnectionEvents(ctx context.Context, req *publishingpb.PublishChannelConnectionEventsRequest, opts ...gax.CallOption) (*publishingpb.PublishChannelConnectionEventsResponse, error) {
162 return c.internalClient.PublishChannelConnectionEvents(ctx, req, opts...)
163 }
164
165 // PublishEvents publish events to a subscriber’s channel.
166 func (c *PublisherClient) PublishEvents(ctx context.Context, req *publishingpb.PublishEventsRequest, opts ...gax.CallOption) (*publishingpb.PublishEventsResponse, error) {
167 return c.internalClient.PublishEvents(ctx, req, opts...)
168 }
169
170 // Publish publish events to a message bus.
171 func (c *PublisherClient) Publish(ctx context.Context, req *publishingpb.PublishRequest, opts ...gax.CallOption) (*publishingpb.PublishResponse, error) {
172 return c.internalClient.Publish(ctx, req, opts...)
173 }
174
175 // publisherGRPCClient is a client for interacting with Eventarc Publishing API over gRPC transport.
176 //
177 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
178 type publisherGRPCClient struct {
179 // Connection pool of gRPC connections to the service.
180 connPool gtransport.ConnPool
181
182 // Points back to the CallOptions field of the containing PublisherClient
183 CallOptions **PublisherCallOptions
184
185 // The gRPC API client.
186 publisherClient publishingpb.PublisherClient
187
188 // The x-goog-* metadata to be sent with each request.
189 xGoogHeaders []string
190
191 logger *slog.Logger
192 }
193
194 // NewPublisherClient creates a new publisher client based on gRPC.
195 // The returned client must be Closed when it is done being used to clean up its underlying connections.
196 //
197 // Eventarc processes events generated by an event provider and delivers them to
198 // a subscriber.
199 //
200 // An event provider is a software-as-a-service (SaaS) system or
201 // product that can generate and deliver events through Eventarc.
202 //
203 // A third-party event provider is an event provider from outside of Google.
204 //
205 // A partner is a third-party event provider that is integrated with Eventarc.
206 //
207 // A subscriber is a Google Cloud customer interested in receiving events.
208 //
209 // Channel is a first-class Eventarc resource that is created and managed
210 // by the subscriber in their Google Cloud project. A Channel represents a
211 // subscriber’s intent to receive events from an event provider. A Channel is
212 // associated with exactly one event provider.
213 //
214 // ChannelConnection is a first-class Eventarc resource that
215 // is created and managed by the partner in their Google Cloud project. A
216 // ChannelConnection represents a connection between a partner and a
217 // subscriber’s Channel. A ChannelConnection has a one-to-one mapping with a
218 // Channel.
219 //
220 // Bus is a first-class Eventarc resource that is created and managed in a
221 // Google Cloud project. A Bus provides a discoverable endpoint for events and
222 // is a router that receives all events published by event providers and
223 // delivers them to zero or more subscribers.
224 //
225 // Publisher allows an event provider to publish events to Eventarc.
226 func NewPublisherClient(ctx context.Context, opts ...option.ClientOption) (*PublisherClient, error) {
227 clientOpts := defaultPublisherGRPCClientOptions()
228 if newPublisherClientHook != nil {
229 hookOpts, err := newPublisherClientHook(ctx, clientHookParams{})
230 if err != nil {
231 return nil, err
232 }
233 clientOpts = append(clientOpts, hookOpts...)
234 }
235
236 connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...)
237 if err != nil {
238 return nil, err
239 }
240 client := PublisherClient{CallOptions: defaultPublisherCallOptions()}
241
242 c := &publisherGRPCClient{
243 connPool: connPool,
244 publisherClient: publishingpb.NewPublisherClient(connPool),
245 CallOptions: &client.CallOptions,
246 logger: internaloption.GetLogger(opts),
247 }
248 c.setGoogleClientInfo()
249
250 client.internalClient = c
251
252 return &client, nil
253 }
254
255 // Connection returns a connection to the API service.
256 //
257 // Deprecated: Connections are now pooled so this method does not always
258 // return the same resource.
259 func (c *publisherGRPCClient) Connection() *grpc.ClientConn {
260 return c.connPool.Conn()
261 }
262
263 // setGoogleClientInfo sets the name and version of the application in
264 // the `x-goog-api-client` header passed on each request. Intended for
265 // use by Google-written clients.
266 func (c *publisherGRPCClient) setGoogleClientInfo(keyval ...string) {
267 kv := append([]string{"gl-go", gax.GoVersion}, keyval...)
268 kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "grpc", grpc.Version, "pb", protoVersion)
269 c.xGoogHeaders = []string{
270 "x-goog-api-client", gax.XGoogHeader(kv...),
271 }
272 }
273
274 // Close closes the connection to the API service. The user should invoke this when
275 // the client is no longer required.
276 func (c *publisherGRPCClient) Close() error {
277 return c.connPool.Close()
278 }
279
280 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
281 type publisherRESTClient struct {
282 // The http endpoint to connect to.
283 endpoint string
284
285 // The http client.
286 httpClient *http.Client
287
288 // The x-goog-* headers to be sent with each request.
289 xGoogHeaders []string
290
291 // Points back to the CallOptions field of the containing PublisherClient
292 CallOptions **PublisherCallOptions
293
294 logger *slog.Logger
295 }
296
297 // NewPublisherRESTClient creates a new publisher rest client.
298 //
299 // Eventarc processes events generated by an event provider and delivers them to
300 // a subscriber.
301 //
302 // An event provider is a software-as-a-service (SaaS) system or
303 // product that can generate and deliver events through Eventarc.
304 //
305 // A third-party event provider is an event provider from outside of Google.
306 //
307 // A partner is a third-party event provider that is integrated with Eventarc.
308 //
309 // A subscriber is a Google Cloud customer interested in receiving events.
310 //
311 // Channel is a first-class Eventarc resource that is created and managed
312 // by the subscriber in their Google Cloud project. A Channel represents a
313 // subscriber’s intent to receive events from an event provider. A Channel is
314 // associated with exactly one event provider.
315 //
316 // ChannelConnection is a first-class Eventarc resource that
317 // is created and managed by the partner in their Google Cloud project. A
318 // ChannelConnection represents a connection between a partner and a
319 // subscriber’s Channel. A ChannelConnection has a one-to-one mapping with a
320 // Channel.
321 //
322 // Bus is a first-class Eventarc resource that is created and managed in a
323 // Google Cloud project. A Bus provides a discoverable endpoint for events and
324 // is a router that receives all events published by event providers and
325 // delivers them to zero or more subscribers.
326 //
327 // Publisher allows an event provider to publish events to Eventarc.
328 func NewPublisherRESTClient(ctx context.Context, opts ...option.ClientOption) (*PublisherClient, error) {
329 clientOpts := append(defaultPublisherRESTClientOptions(), opts...)
330 httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...)
331 if err != nil {
332 return nil, err
333 }
334
335 callOpts := defaultPublisherRESTCallOptions()
336 c := &publisherRESTClient{
337 endpoint: endpoint,
338 httpClient: httpClient,
339 CallOptions: &callOpts,
340 logger: internaloption.GetLogger(opts),
341 }
342 c.setGoogleClientInfo()
343
344 return &PublisherClient{internalClient: c, CallOptions: callOpts}, nil
345 }
346
347 func defaultPublisherRESTClientOptions() []option.ClientOption {
348 return []option.ClientOption{
349 internaloption.WithDefaultEndpoint("https://eventarcpublishing.googleapis.com"),
350 internaloption.WithDefaultEndpointTemplate("https://eventarcpublishing.UNIVERSE_DOMAIN"),
351 internaloption.WithDefaultMTLSEndpoint("https://eventarcpublishing.mtls.googleapis.com"),
352 internaloption.WithDefaultUniverseDomain("googleapis.com"),
353 internaloption.WithDefaultAudience("https://eventarcpublishing.googleapis.com/"),
354 internaloption.WithDefaultScopes(DefaultAuthScopes()...),
355 internaloption.EnableNewAuthLibrary(),
356 }
357 }
358
359 // setGoogleClientInfo sets the name and version of the application in
360 // the `x-goog-api-client` header passed on each request. Intended for
361 // use by Google-written clients.
362 func (c *publisherRESTClient) setGoogleClientInfo(keyval ...string) {
363 kv := append([]string{"gl-go", gax.GoVersion}, keyval...)
364 kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "rest", "UNKNOWN", "pb", protoVersion)
365 c.xGoogHeaders = []string{
366 "x-goog-api-client", gax.XGoogHeader(kv...),
367 }
368 }
369
370 // Close closes the connection to the API service. The user should invoke this when
371 // the client is no longer required.
372 func (c *publisherRESTClient) Close() error {
373 // Replace httpClient with nil to force cleanup.
374 c.httpClient = nil
375 return nil
376 }
377
378 // Connection returns a connection to the API service.
379 //
380 // Deprecated: This method always returns nil.
381 func (c *publisherRESTClient) Connection() *grpc.ClientConn {
382 return nil
383 }
384 func (c *publisherGRPCClient) PublishChannelConnectionEvents(ctx context.Context, req *publishingpb.PublishChannelConnectionEventsRequest, opts ...gax.CallOption) (*publishingpb.PublishChannelConnectionEventsResponse, error) {
385 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "channel_connection", url.QueryEscape(req.GetChannelConnection()))}
386
387 hds = append(c.xGoogHeaders, hds...)
388 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
389 opts = append((*c.CallOptions).PublishChannelConnectionEvents[0:len((*c.CallOptions).PublishChannelConnectionEvents):len((*c.CallOptions).PublishChannelConnectionEvents)], opts...)
390 var resp *publishingpb.PublishChannelConnectionEventsResponse
391 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
392 var err error
393 resp, err = executeRPC(ctx, c.publisherClient.PublishChannelConnectionEvents, req, settings.GRPC, c.logger, "PublishChannelConnectionEvents")
394 return err
395 }, opts...)
396 if err != nil {
397 return nil, err
398 }
399 return resp, nil
400 }
401
402 func (c *publisherGRPCClient) PublishEvents(ctx context.Context, req *publishingpb.PublishEventsRequest, opts ...gax.CallOption) (*publishingpb.PublishEventsResponse, error) {
403 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "channel", url.QueryEscape(req.GetChannel()))}
404
405 hds = append(c.xGoogHeaders, hds...)
406 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
407 opts = append((*c.CallOptions).PublishEvents[0:len((*c.CallOptions).PublishEvents):len((*c.CallOptions).PublishEvents)], opts...)
408 var resp *publishingpb.PublishEventsResponse
409 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
410 var err error
411 resp, err = executeRPC(ctx, c.publisherClient.PublishEvents, req, settings.GRPC, c.logger, "PublishEvents")
412 return err
413 }, opts...)
414 if err != nil {
415 return nil, err
416 }
417 return resp, nil
418 }
419
420 func (c *publisherGRPCClient) Publish(ctx context.Context, req *publishingpb.PublishRequest, opts ...gax.CallOption) (*publishingpb.PublishResponse, error) {
421 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "message_bus", url.QueryEscape(req.GetMessageBus()))}
422
423 hds = append(c.xGoogHeaders, hds...)
424 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
425 opts = append((*c.CallOptions).Publish[0:len((*c.CallOptions).Publish):len((*c.CallOptions).Publish)], opts...)
426 var resp *publishingpb.PublishResponse
427 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
428 var err error
429 resp, err = executeRPC(ctx, c.publisherClient.Publish, req, settings.GRPC, c.logger, "Publish")
430 return err
431 }, opts...)
432 if err != nil {
433 return nil, err
434 }
435 return resp, nil
436 }
437
438 // PublishChannelConnectionEvents publish events to a ChannelConnection in a partner’s project.
439 func (c *publisherRESTClient) PublishChannelConnectionEvents(ctx context.Context, req *publishingpb.PublishChannelConnectionEventsRequest, opts ...gax.CallOption) (*publishingpb.PublishChannelConnectionEventsResponse, error) {
440 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
441 jsonReq, err := m.Marshal(req)
442 if err != nil {
443 return nil, err
444 }
445
446 baseUrl, err := url.Parse(c.endpoint)
447 if err != nil {
448 return nil, err
449 }
450 baseUrl.Path += fmt.Sprintf("/v1/%v:publishEvents", req.GetChannelConnection())
451
452 params := url.Values{}
453 params.Add("$alt", "json;enum-encoding=int")
454
455 baseUrl.RawQuery = params.Encode()
456
457 // Build HTTP headers from client and context metadata.
458 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "channel_connection", url.QueryEscape(req.GetChannelConnection()))}
459
460 hds = append(c.xGoogHeaders, hds...)
461 hds = append(hds, "Content-Type", "application/json")
462 headers := gax.BuildHeaders(ctx, hds...)
463 opts = append((*c.CallOptions).PublishChannelConnectionEvents[0:len((*c.CallOptions).PublishChannelConnectionEvents):len((*c.CallOptions).PublishChannelConnectionEvents)], opts...)
464 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
465 resp := &publishingpb.PublishChannelConnectionEventsResponse{}
466 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
467 if settings.Path != "" {
468 baseUrl.Path = settings.Path
469 }
470 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
471 if err != nil {
472 return err
473 }
474 httpReq = httpReq.WithContext(ctx)
475 httpReq.Header = headers
476
477 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "PublishChannelConnectionEvents")
478 if err != nil {
479 return err
480 }
481
482 if err := unm.Unmarshal(buf, resp); err != nil {
483 return err
484 }
485
486 return nil
487 }, opts...)
488 if e != nil {
489 return nil, e
490 }
491 return resp, nil
492 }
493
494 // PublishEvents publish events to a subscriber’s channel.
495 func (c *publisherRESTClient) PublishEvents(ctx context.Context, req *publishingpb.PublishEventsRequest, opts ...gax.CallOption) (*publishingpb.PublishEventsResponse, error) {
496 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
497 jsonReq, err := m.Marshal(req)
498 if err != nil {
499 return nil, err
500 }
501
502 baseUrl, err := url.Parse(c.endpoint)
503 if err != nil {
504 return nil, err
505 }
506 baseUrl.Path += fmt.Sprintf("/v1/%v:publishEvents", req.GetChannel())
507
508 params := url.Values{}
509 params.Add("$alt", "json;enum-encoding=int")
510
511 baseUrl.RawQuery = params.Encode()
512
513 // Build HTTP headers from client and context metadata.
514 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "channel", url.QueryEscape(req.GetChannel()))}
515
516 hds = append(c.xGoogHeaders, hds...)
517 hds = append(hds, "Content-Type", "application/json")
518 headers := gax.BuildHeaders(ctx, hds...)
519 opts = append((*c.CallOptions).PublishEvents[0:len((*c.CallOptions).PublishEvents):len((*c.CallOptions).PublishEvents)], opts...)
520 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
521 resp := &publishingpb.PublishEventsResponse{}
522 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
523 if settings.Path != "" {
524 baseUrl.Path = settings.Path
525 }
526 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
527 if err != nil {
528 return err
529 }
530 httpReq = httpReq.WithContext(ctx)
531 httpReq.Header = headers
532
533 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "PublishEvents")
534 if err != nil {
535 return err
536 }
537
538 if err := unm.Unmarshal(buf, resp); err != nil {
539 return err
540 }
541
542 return nil
543 }, opts...)
544 if e != nil {
545 return nil, e
546 }
547 return resp, nil
548 }
549
550 // Publish publish events to a message bus.
551 func (c *publisherRESTClient) Publish(ctx context.Context, req *publishingpb.PublishRequest, opts ...gax.CallOption) (*publishingpb.PublishResponse, error) {
552 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
553 jsonReq, err := m.Marshal(req)
554 if err != nil {
555 return nil, err
556 }
557
558 baseUrl, err := url.Parse(c.endpoint)
559 if err != nil {
560 return nil, err
561 }
562 baseUrl.Path += fmt.Sprintf("/v1/%v:publish", req.GetMessageBus())
563
564 params := url.Values{}
565 params.Add("$alt", "json;enum-encoding=int")
566
567 baseUrl.RawQuery = params.Encode()
568
569 // Build HTTP headers from client and context metadata.
570 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "message_bus", url.QueryEscape(req.GetMessageBus()))}
571
572 hds = append(c.xGoogHeaders, hds...)
573 hds = append(hds, "Content-Type", "application/json")
574 headers := gax.BuildHeaders(ctx, hds...)
575 opts = append((*c.CallOptions).Publish[0:len((*c.CallOptions).Publish):len((*c.CallOptions).Publish)], opts...)
576 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
577 resp := &publishingpb.PublishResponse{}
578 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
579 if settings.Path != "" {
580 baseUrl.Path = settings.Path
581 }
582 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
583 if err != nil {
584 return err
585 }
586 httpReq = httpReq.WithContext(ctx)
587 httpReq.Header = headers
588
589 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "Publish")
590 if err != nil {
591 return err
592 }
593
594 if err := unm.Unmarshal(buf, resp); err != nil {
595 return err
596 }
597
598 return nil
599 }, opts...)
600 if e != nil {
601 return nil, e
602 }
603 return resp, nil
604 }