Debian Codegraph @

shopping/merchant/lfp/apiv1/lfp_merchant_state_client.go

raw
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 lfp
18
19 import (
20 "context"
21 "fmt"
22 "log/slog"
23 "math"
24 "net/http"
25 "net/url"
26 "time"
27
28 lfppb "cloud.google.com/go/shopping/merchant/lfp/apiv1/lfppb"
29 gax "github.com/googleapis/gax-go/v2"
30 "google.golang.org/api/option"
31 "google.golang.org/api/option/internaloption"
32 gtransport "google.golang.org/api/transport/grpc"
33 httptransport "google.golang.org/api/transport/http"
34 "google.golang.org/grpc"
35 "google.golang.org/grpc/codes"
36 "google.golang.org/protobuf/encoding/protojson"
37 )
38
39 var newLfpMerchantStateClientHook clientHook
40
41 // LfpMerchantStateCallOptions contains the retry settings for each method of LfpMerchantStateClient.
42 type LfpMerchantStateCallOptions struct {
43 GetLfpMerchantState []gax.CallOption
44 }
45
46 func defaultLfpMerchantStateGRPCClientOptions() []option.ClientOption {
47 return []option.ClientOption{
48 internaloption.WithDefaultEndpoint("merchantapi.googleapis.com:443"),
49 internaloption.WithDefaultEndpointTemplate("merchantapi.UNIVERSE_DOMAIN:443"),
50 internaloption.WithDefaultMTLSEndpoint("merchantapi.mtls.googleapis.com:443"),
51 internaloption.WithDefaultUniverseDomain("googleapis.com"),
52 internaloption.WithDefaultAudience("https://merchantapi.googleapis.com/"),
53 internaloption.WithDefaultScopes(DefaultAuthScopes()...),
54 internaloption.EnableJwtWithScope(),
55 internaloption.EnableNewAuthLibrary(),
56 option.WithGRPCDialOption(grpc.WithDefaultCallOptions(
57 grpc.MaxCallRecvMsgSize(math.MaxInt32))),
58 }
59 }
60
61 func defaultLfpMerchantStateCallOptions() *LfpMerchantStateCallOptions {
62 return &LfpMerchantStateCallOptions{
63 GetLfpMerchantState: []gax.CallOption{
64 gax.WithTimeout(60000 * time.Millisecond),
65 gax.WithRetry(func() gax.Retryer {
66 return gax.OnCodes([]codes.Code{
67 codes.Unavailable,
68 }, gax.Backoff{
69 Initial: 1000 * time.Millisecond,
70 Max: 10000 * time.Millisecond,
71 Multiplier: 1.30,
72 })
73 }),
74 },
75 }
76 }
77
78 func defaultLfpMerchantStateRESTCallOptions() *LfpMerchantStateCallOptions {
79 return &LfpMerchantStateCallOptions{
80 GetLfpMerchantState: []gax.CallOption{
81 gax.WithTimeout(60000 * time.Millisecond),
82 gax.WithRetry(func() gax.Retryer {
83 return gax.OnHTTPCodes(gax.Backoff{
84 Initial: 1000 * time.Millisecond,
85 Max: 10000 * time.Millisecond,
86 Multiplier: 1.30,
87 },
88 http.StatusServiceUnavailable)
89 }),
90 },
91 }
92 }
93
94 // internalLfpMerchantStateClient is an interface that defines the methods available from Merchant API.
95 type internalLfpMerchantStateClient interface {
96 Close() error
97 setGoogleClientInfo(...string)
98 Connection() *grpc.ClientConn
99 GetLfpMerchantState(context.Context, *lfppb.GetLfpMerchantStateRequest, ...gax.CallOption) (*lfppb.LfpMerchantState, error)
100 }
101
102 // LfpMerchantStateClient is a client for interacting with Merchant API.
103 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
104 //
105 // Service for a LFP
106 // partner (at https://support.google.com/merchants/answer/7676652) to get the
107 // state of a merchant.
108 //
109 // For information about onboarding a retailer, see How to onboard a
110 // retailer (at https://support.google.com/merchants/answer/15243706).
111 type LfpMerchantStateClient struct {
112 // The internal transport-dependent client.
113 internalClient internalLfpMerchantStateClient
114
115 // The call options for this service.
116 CallOptions *LfpMerchantStateCallOptions
117 }
118
119 // Wrapper methods routed to the internal client.
120
121 // Close closes the connection to the API service. The user should invoke this when
122 // the client is no longer required.
123 func (c *LfpMerchantStateClient) Close() error {
124 return c.internalClient.Close()
125 }
126
127 // setGoogleClientInfo sets the name and version of the application in
128 // the `x-goog-api-client` header passed on each request. Intended for
129 // use by Google-written clients.
130 func (c *LfpMerchantStateClient) setGoogleClientInfo(keyval ...string) {
131 c.internalClient.setGoogleClientInfo(keyval...)
132 }
133
134 // Connection returns a connection to the API service.
135 //
136 // Deprecated: Connections are now pooled so this method does not always
137 // return the same resource.
138 func (c *LfpMerchantStateClient) Connection() *grpc.ClientConn {
139 return c.internalClient.Connection()
140 }
141
142 // GetLfpMerchantState gets the LFP state of a merchant
143 func (c *LfpMerchantStateClient) GetLfpMerchantState(ctx context.Context, req *lfppb.GetLfpMerchantStateRequest, opts ...gax.CallOption) (*lfppb.LfpMerchantState, error) {
144 return c.internalClient.GetLfpMerchantState(ctx, req, opts...)
145 }
146
147 // lfpMerchantStateGRPCClient is a client for interacting with Merchant API over gRPC transport.
148 //
149 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
150 type lfpMerchantStateGRPCClient struct {
151 // Connection pool of gRPC connections to the service.
152 connPool gtransport.ConnPool
153
154 // Points back to the CallOptions field of the containing LfpMerchantStateClient
155 CallOptions **LfpMerchantStateCallOptions
156
157 // The gRPC API client.
158 lfpMerchantStateClient lfppb.LfpMerchantStateServiceClient
159
160 // The x-goog-* metadata to be sent with each request.
161 xGoogHeaders []string
162
163 logger *slog.Logger
164 }
165
166 // NewLfpMerchantStateClient creates a new lfp merchant state service client based on gRPC.
167 // The returned client must be Closed when it is done being used to clean up its underlying connections.
168 //
169 // Service for a LFP
170 // partner (at https://support.google.com/merchants/answer/7676652) to get the
171 // state of a merchant.
172 //
173 // For information about onboarding a retailer, see How to onboard a
174 // retailer (at https://support.google.com/merchants/answer/15243706).
175 func NewLfpMerchantStateClient(ctx context.Context, opts ...option.ClientOption) (*LfpMerchantStateClient, error) {
176 clientOpts := defaultLfpMerchantStateGRPCClientOptions()
177 if newLfpMerchantStateClientHook != nil {
178 hookOpts, err := newLfpMerchantStateClientHook(ctx, clientHookParams{})
179 if err != nil {
180 return nil, err
181 }
182 clientOpts = append(clientOpts, hookOpts...)
183 }
184
185 connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...)
186 if err != nil {
187 return nil, err
188 }
189 client := LfpMerchantStateClient{CallOptions: defaultLfpMerchantStateCallOptions()}
190
191 c := &lfpMerchantStateGRPCClient{
192 connPool: connPool,
193 lfpMerchantStateClient: lfppb.NewLfpMerchantStateServiceClient(connPool),
194 CallOptions: &client.CallOptions,
195 logger: internaloption.GetLogger(opts),
196 }
197 c.setGoogleClientInfo()
198
199 client.internalClient = c
200
201 return &client, nil
202 }
203
204 // Connection returns a connection to the API service.
205 //
206 // Deprecated: Connections are now pooled so this method does not always
207 // return the same resource.
208 func (c *lfpMerchantStateGRPCClient) Connection() *grpc.ClientConn {
209 return c.connPool.Conn()
210 }
211
212 // setGoogleClientInfo sets the name and version of the application in
213 // the `x-goog-api-client` header passed on each request. Intended for
214 // use by Google-written clients.
215 func (c *lfpMerchantStateGRPCClient) setGoogleClientInfo(keyval ...string) {
216 kv := append([]string{"gl-go", gax.GoVersion}, keyval...)
217 kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "grpc", grpc.Version, "pb", protoVersion)
218 c.xGoogHeaders = []string{
219 "x-goog-api-client", gax.XGoogHeader(kv...),
220 }
221 }
222
223 // Close closes the connection to the API service. The user should invoke this when
224 // the client is no longer required.
225 func (c *lfpMerchantStateGRPCClient) Close() error {
226 return c.connPool.Close()
227 }
228
229 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
230 type lfpMerchantStateRESTClient struct {
231 // The http endpoint to connect to.
232 endpoint string
233
234 // The http client.
235 httpClient *http.Client
236
237 // The x-goog-* headers to be sent with each request.
238 xGoogHeaders []string
239
240 // Points back to the CallOptions field of the containing LfpMerchantStateClient
241 CallOptions **LfpMerchantStateCallOptions
242
243 logger *slog.Logger
244 }
245
246 // NewLfpMerchantStateRESTClient creates a new lfp merchant state service rest client.
247 //
248 // Service for a LFP
249 // partner (at https://support.google.com/merchants/answer/7676652) to get the
250 // state of a merchant.
251 //
252 // For information about onboarding a retailer, see How to onboard a
253 // retailer (at https://support.google.com/merchants/answer/15243706).
254 func NewLfpMerchantStateRESTClient(ctx context.Context, opts ...option.ClientOption) (*LfpMerchantStateClient, error) {
255 clientOpts := append(defaultLfpMerchantStateRESTClientOptions(), opts...)
256 httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...)
257 if err != nil {
258 return nil, err
259 }
260
261 callOpts := defaultLfpMerchantStateRESTCallOptions()
262 c := &lfpMerchantStateRESTClient{
263 endpoint: endpoint,
264 httpClient: httpClient,
265 CallOptions: &callOpts,
266 logger: internaloption.GetLogger(opts),
267 }
268 c.setGoogleClientInfo()
269
270 return &LfpMerchantStateClient{internalClient: c, CallOptions: callOpts}, nil
271 }
272
273 func defaultLfpMerchantStateRESTClientOptions() []option.ClientOption {
274 return []option.ClientOption{
275 internaloption.WithDefaultEndpoint("https://merchantapi.googleapis.com"),
276 internaloption.WithDefaultEndpointTemplate("https://merchantapi.UNIVERSE_DOMAIN"),
277 internaloption.WithDefaultMTLSEndpoint("https://merchantapi.mtls.googleapis.com"),
278 internaloption.WithDefaultUniverseDomain("googleapis.com"),
279 internaloption.WithDefaultAudience("https://merchantapi.googleapis.com/"),
280 internaloption.WithDefaultScopes(DefaultAuthScopes()...),
281 internaloption.EnableNewAuthLibrary(),
282 }
283 }
284
285 // setGoogleClientInfo sets the name and version of the application in
286 // the `x-goog-api-client` header passed on each request. Intended for
287 // use by Google-written clients.
288 func (c *lfpMerchantStateRESTClient) setGoogleClientInfo(keyval ...string) {
289 kv := append([]string{"gl-go", gax.GoVersion}, keyval...)
290 kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "rest", "UNKNOWN", "pb", protoVersion)
291 c.xGoogHeaders = []string{
292 "x-goog-api-client", gax.XGoogHeader(kv...),
293 }
294 }
295
296 // Close closes the connection to the API service. The user should invoke this when
297 // the client is no longer required.
298 func (c *lfpMerchantStateRESTClient) Close() error {
299 // Replace httpClient with nil to force cleanup.
300 c.httpClient = nil
301 return nil
302 }
303
304 // Connection returns a connection to the API service.
305 //
306 // Deprecated: This method always returns nil.
307 func (c *lfpMerchantStateRESTClient) Connection() *grpc.ClientConn {
308 return nil
309 }
310 func (c *lfpMerchantStateGRPCClient) GetLfpMerchantState(ctx context.Context, req *lfppb.GetLfpMerchantStateRequest, opts ...gax.CallOption) (*lfppb.LfpMerchantState, error) {
311 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
312
313 hds = append(c.xGoogHeaders, hds...)
314 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
315 opts = append((*c.CallOptions).GetLfpMerchantState[0:len((*c.CallOptions).GetLfpMerchantState):len((*c.CallOptions).GetLfpMerchantState)], opts...)
316 var resp *lfppb.LfpMerchantState
317 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
318 var err error
319 resp, err = executeRPC(ctx, c.lfpMerchantStateClient.GetLfpMerchantState, req, settings.GRPC, c.logger, "GetLfpMerchantState")
320 return err
321 }, opts...)
322 if err != nil {
323 return nil, err
324 }
325 return resp, nil
326 }
327
328 // GetLfpMerchantState gets the LFP state of a merchant
329 func (c *lfpMerchantStateRESTClient) GetLfpMerchantState(ctx context.Context, req *lfppb.GetLfpMerchantStateRequest, opts ...gax.CallOption) (*lfppb.LfpMerchantState, error) {
330 baseUrl, err := url.Parse(c.endpoint)
331 if err != nil {
332 return nil, err
333 }
334 baseUrl.Path += fmt.Sprintf("/lfp/v1/%v", req.GetName())
335
336 params := url.Values{}
337 params.Add("$alt", "json;enum-encoding=int")
338
339 baseUrl.RawQuery = params.Encode()
340
341 // Build HTTP headers from client and context metadata.
342 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
343
344 hds = append(c.xGoogHeaders, hds...)
345 hds = append(hds, "Content-Type", "application/json")
346 headers := gax.BuildHeaders(ctx, hds...)
347 opts = append((*c.CallOptions).GetLfpMerchantState[0:len((*c.CallOptions).GetLfpMerchantState):len((*c.CallOptions).GetLfpMerchantState)], opts...)
348 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
349 resp := &lfppb.LfpMerchantState{}
350 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
351 if settings.Path != "" {
352 baseUrl.Path = settings.Path
353 }
354 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
355 if err != nil {
356 return err
357 }
358 httpReq = httpReq.WithContext(ctx)
359 httpReq.Header = headers
360
361 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetLfpMerchantState")
362 if err != nil {
363 return err
364 }
365
366 if err := unm.Unmarshal(buf, resp); err != nil {
367 return err
368 }
369
370 return nil
371 }, opts...)
372 if e != nil {
373 return nil, e
374 }
375 return resp, nil
376 }