Debian Codegraph @

shopping/merchant/lfp/apiv1beta/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/apiv1beta/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 type LfpMerchantStateClient struct {
109 // The internal transport-dependent client.
110 internalClient internalLfpMerchantStateClient
111
112 // The call options for this service.
113 CallOptions *LfpMerchantStateCallOptions
114 }
115
116 // Wrapper methods routed to the internal client.
117
118 // Close closes the connection to the API service. The user should invoke this when
119 // the client is no longer required.
120 func (c *LfpMerchantStateClient) Close() error {
121 return c.internalClient.Close()
122 }
123
124 // setGoogleClientInfo sets the name and version of the application in
125 // the `x-goog-api-client` header passed on each request. Intended for
126 // use by Google-written clients.
127 func (c *LfpMerchantStateClient) setGoogleClientInfo(keyval ...string) {
128 c.internalClient.setGoogleClientInfo(keyval...)
129 }
130
131 // Connection returns a connection to the API service.
132 //
133 // Deprecated: Connections are now pooled so this method does not always
134 // return the same resource.
135 func (c *LfpMerchantStateClient) Connection() *grpc.ClientConn {
136 return c.internalClient.Connection()
137 }
138
139 // GetLfpMerchantState gets the LFP state of a merchant
140 func (c *LfpMerchantStateClient) GetLfpMerchantState(ctx context.Context, req *lfppb.GetLfpMerchantStateRequest, opts ...gax.CallOption) (*lfppb.LfpMerchantState, error) {
141 return c.internalClient.GetLfpMerchantState(ctx, req, opts...)
142 }
143
144 // lfpMerchantStateGRPCClient is a client for interacting with Merchant API over gRPC transport.
145 //
146 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
147 type lfpMerchantStateGRPCClient struct {
148 // Connection pool of gRPC connections to the service.
149 connPool gtransport.ConnPool
150
151 // Points back to the CallOptions field of the containing LfpMerchantStateClient
152 CallOptions **LfpMerchantStateCallOptions
153
154 // The gRPC API client.
155 lfpMerchantStateClient lfppb.LfpMerchantStateServiceClient
156
157 // The x-goog-* metadata to be sent with each request.
158 xGoogHeaders []string
159
160 logger *slog.Logger
161 }
162
163 // NewLfpMerchantStateClient creates a new lfp merchant state service client based on gRPC.
164 // The returned client must be Closed when it is done being used to clean up its underlying connections.
165 //
166 // Service for a LFP
167 // partner (at https://support.google.com/merchants/answer/7676652) to get the
168 // state of a merchant.
169 func NewLfpMerchantStateClient(ctx context.Context, opts ...option.ClientOption) (*LfpMerchantStateClient, error) {
170 clientOpts := defaultLfpMerchantStateGRPCClientOptions()
171 if newLfpMerchantStateClientHook != nil {
172 hookOpts, err := newLfpMerchantStateClientHook(ctx, clientHookParams{})
173 if err != nil {
174 return nil, err
175 }
176 clientOpts = append(clientOpts, hookOpts...)
177 }
178
179 connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...)
180 if err != nil {
181 return nil, err
182 }
183 client := LfpMerchantStateClient{CallOptions: defaultLfpMerchantStateCallOptions()}
184
185 c := &lfpMerchantStateGRPCClient{
186 connPool: connPool,
187 lfpMerchantStateClient: lfppb.NewLfpMerchantStateServiceClient(connPool),
188 CallOptions: &client.CallOptions,
189 logger: internaloption.GetLogger(opts),
190 }
191 c.setGoogleClientInfo()
192
193 client.internalClient = c
194
195 return &client, nil
196 }
197
198 // Connection returns a connection to the API service.
199 //
200 // Deprecated: Connections are now pooled so this method does not always
201 // return the same resource.
202 func (c *lfpMerchantStateGRPCClient) Connection() *grpc.ClientConn {
203 return c.connPool.Conn()
204 }
205
206 // setGoogleClientInfo sets the name and version of the application in
207 // the `x-goog-api-client` header passed on each request. Intended for
208 // use by Google-written clients.
209 func (c *lfpMerchantStateGRPCClient) setGoogleClientInfo(keyval ...string) {
210 kv := append([]string{"gl-go", gax.GoVersion}, keyval...)
211 kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "grpc", grpc.Version, "pb", protoVersion)
212 c.xGoogHeaders = []string{
213 "x-goog-api-client", gax.XGoogHeader(kv...),
214 }
215 }
216
217 // Close closes the connection to the API service. The user should invoke this when
218 // the client is no longer required.
219 func (c *lfpMerchantStateGRPCClient) Close() error {
220 return c.connPool.Close()
221 }
222
223 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
224 type lfpMerchantStateRESTClient struct {
225 // The http endpoint to connect to.
226 endpoint string
227
228 // The http client.
229 httpClient *http.Client
230
231 // The x-goog-* headers to be sent with each request.
232 xGoogHeaders []string
233
234 // Points back to the CallOptions field of the containing LfpMerchantStateClient
235 CallOptions **LfpMerchantStateCallOptions
236
237 logger *slog.Logger
238 }
239
240 // NewLfpMerchantStateRESTClient creates a new lfp merchant state service rest client.
241 //
242 // Service for a LFP
243 // partner (at https://support.google.com/merchants/answer/7676652) to get the
244 // state of a merchant.
245 func NewLfpMerchantStateRESTClient(ctx context.Context, opts ...option.ClientOption) (*LfpMerchantStateClient, error) {
246 clientOpts := append(defaultLfpMerchantStateRESTClientOptions(), opts...)
247 httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...)
248 if err != nil {
249 return nil, err
250 }
251
252 callOpts := defaultLfpMerchantStateRESTCallOptions()
253 c := &lfpMerchantStateRESTClient{
254 endpoint: endpoint,
255 httpClient: httpClient,
256 CallOptions: &callOpts,
257 logger: internaloption.GetLogger(opts),
258 }
259 c.setGoogleClientInfo()
260
261 return &LfpMerchantStateClient{internalClient: c, CallOptions: callOpts}, nil
262 }
263
264 func defaultLfpMerchantStateRESTClientOptions() []option.ClientOption {
265 return []option.ClientOption{
266 internaloption.WithDefaultEndpoint("https://merchantapi.googleapis.com"),
267 internaloption.WithDefaultEndpointTemplate("https://merchantapi.UNIVERSE_DOMAIN"),
268 internaloption.WithDefaultMTLSEndpoint("https://merchantapi.mtls.googleapis.com"),
269 internaloption.WithDefaultUniverseDomain("googleapis.com"),
270 internaloption.WithDefaultAudience("https://merchantapi.googleapis.com/"),
271 internaloption.WithDefaultScopes(DefaultAuthScopes()...),
272 internaloption.EnableNewAuthLibrary(),
273 }
274 }
275
276 // setGoogleClientInfo sets the name and version of the application in
277 // the `x-goog-api-client` header passed on each request. Intended for
278 // use by Google-written clients.
279 func (c *lfpMerchantStateRESTClient) setGoogleClientInfo(keyval ...string) {
280 kv := append([]string{"gl-go", gax.GoVersion}, keyval...)
281 kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "rest", "UNKNOWN", "pb", protoVersion)
282 c.xGoogHeaders = []string{
283 "x-goog-api-client", gax.XGoogHeader(kv...),
284 }
285 }
286
287 // Close closes the connection to the API service. The user should invoke this when
288 // the client is no longer required.
289 func (c *lfpMerchantStateRESTClient) Close() error {
290 // Replace httpClient with nil to force cleanup.
291 c.httpClient = nil
292 return nil
293 }
294
295 // Connection returns a connection to the API service.
296 //
297 // Deprecated: This method always returns nil.
298 func (c *lfpMerchantStateRESTClient) Connection() *grpc.ClientConn {
299 return nil
300 }
301 func (c *lfpMerchantStateGRPCClient) GetLfpMerchantState(ctx context.Context, req *lfppb.GetLfpMerchantStateRequest, opts ...gax.CallOption) (*lfppb.LfpMerchantState, error) {
302 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
303
304 hds = append(c.xGoogHeaders, hds...)
305 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
306 opts = append((*c.CallOptions).GetLfpMerchantState[0:len((*c.CallOptions).GetLfpMerchantState):len((*c.CallOptions).GetLfpMerchantState)], opts...)
307 var resp *lfppb.LfpMerchantState
308 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
309 var err error
310 resp, err = executeRPC(ctx, c.lfpMerchantStateClient.GetLfpMerchantState, req, settings.GRPC, c.logger, "GetLfpMerchantState")
311 return err
312 }, opts...)
313 if err != nil {
314 return nil, err
315 }
316 return resp, nil
317 }
318
319 // GetLfpMerchantState gets the LFP state of a merchant
320 func (c *lfpMerchantStateRESTClient) GetLfpMerchantState(ctx context.Context, req *lfppb.GetLfpMerchantStateRequest, opts ...gax.CallOption) (*lfppb.LfpMerchantState, error) {
321 baseUrl, err := url.Parse(c.endpoint)
322 if err != nil {
323 return nil, err
324 }
325 baseUrl.Path += fmt.Sprintf("/lfp/v1beta/%v", req.GetName())
326
327 params := url.Values{}
328 params.Add("$alt", "json;enum-encoding=int")
329
330 baseUrl.RawQuery = params.Encode()
331
332 // Build HTTP headers from client and context metadata.
333 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
334
335 hds = append(c.xGoogHeaders, hds...)
336 hds = append(hds, "Content-Type", "application/json")
337 headers := gax.BuildHeaders(ctx, hds...)
338 opts = append((*c.CallOptions).GetLfpMerchantState[0:len((*c.CallOptions).GetLfpMerchantState):len((*c.CallOptions).GetLfpMerchantState)], opts...)
339 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
340 resp := &lfppb.LfpMerchantState{}
341 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
342 if settings.Path != "" {
343 baseUrl.Path = settings.Path
344 }
345 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
346 if err != nil {
347 return err
348 }
349 httpReq = httpReq.WithContext(ctx)
350 httpReq.Header = headers
351
352 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetLfpMerchantState")
353 if err != nil {
354 return err
355 }
356
357 if err := unm.Unmarshal(buf, resp); err != nil {
358 return err
359 }
360
361 return nil
362 }, opts...)
363 if e != nil {
364 return nil, e
365 }
366 return resp, nil
367 }