| 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 css |
| 18 |
|
| 19 |
import ( |
| 20 |
"context" |
| 21 |
"fmt" |
| 22 |
"log/slog" |
| 23 |
"math" |
| 24 |
"net/http" |
| 25 |
"net/url" |
| 26 |
"time" |
| 27 |
|
| 28 |
csspb "cloud.google.com/go/shopping/css/apiv1/csspb" |
| 29 |
gax "github.com/googleapis/gax-go/v2" |
| 30 |
"google.golang.org/api/iterator" |
| 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/grpc/codes" |
| 37 |
"google.golang.org/protobuf/encoding/protojson" |
| 38 |
"google.golang.org/protobuf/proto" |
| 39 |
) |
| 40 |
|
| 41 |
var newCssProductsClientHook clientHook |
| 42 |
|
| 43 |
// CssProductsCallOptions contains the retry settings for each method of CssProductsClient. |
| 44 |
type CssProductsCallOptions struct { |
| 45 |
GetCssProduct []gax.CallOption |
| 46 |
ListCssProducts []gax.CallOption |
| 47 |
} |
| 48 |
|
| 49 |
func defaultCssProductsGRPCClientOptions() []option.ClientOption { |
| 50 |
return []option.ClientOption{ |
| 51 |
internaloption.WithDefaultEndpoint("css.googleapis.com:443"), |
| 52 |
internaloption.WithDefaultEndpointTemplate("css.UNIVERSE_DOMAIN:443"), |
| 53 |
internaloption.WithDefaultMTLSEndpoint("css.mtls.googleapis.com:443"), |
| 54 |
internaloption.WithDefaultUniverseDomain("googleapis.com"), |
| 55 |
internaloption.WithDefaultAudience("https://css.googleapis.com/"), |
| 56 |
internaloption.WithDefaultScopes(DefaultAuthScopes()...), |
| 57 |
internaloption.EnableJwtWithScope(), |
| 58 |
internaloption.EnableNewAuthLibrary(), |
| 59 |
option.WithGRPCDialOption(grpc.WithDefaultCallOptions( |
| 60 |
grpc.MaxCallRecvMsgSize(math.MaxInt32))), |
| 61 |
} |
| 62 |
} |
| 63 |
|
| 64 |
func defaultCssProductsCallOptions() *CssProductsCallOptions { |
| 65 |
return &CssProductsCallOptions{ |
| 66 |
GetCssProduct: []gax.CallOption{ |
| 67 |
gax.WithTimeout(60000 * time.Millisecond), |
| 68 |
gax.WithRetry(func() gax.Retryer { |
| 69 |
return gax.OnCodes([]codes.Code{ |
| 70 |
codes.Unavailable, |
| 71 |
}, gax.Backoff{ |
| 72 |
Initial: 1000 * time.Millisecond, |
| 73 |
Max: 10000 * time.Millisecond, |
| 74 |
Multiplier: 1.30, |
| 75 |
}) |
| 76 |
}), |
| 77 |
}, |
| 78 |
ListCssProducts: []gax.CallOption{ |
| 79 |
gax.WithTimeout(60000 * time.Millisecond), |
| 80 |
gax.WithRetry(func() gax.Retryer { |
| 81 |
return gax.OnCodes([]codes.Code{ |
| 82 |
codes.Unavailable, |
| 83 |
}, gax.Backoff{ |
| 84 |
Initial: 1000 * time.Millisecond, |
| 85 |
Max: 10000 * time.Millisecond, |
| 86 |
Multiplier: 1.30, |
| 87 |
}) |
| 88 |
}), |
| 89 |
}, |
| 90 |
} |
| 91 |
} |
| 92 |
|
| 93 |
func defaultCssProductsRESTCallOptions() *CssProductsCallOptions { |
| 94 |
return &CssProductsCallOptions{ |
| 95 |
GetCssProduct: []gax.CallOption{ |
| 96 |
gax.WithTimeout(60000 * time.Millisecond), |
| 97 |
gax.WithRetry(func() gax.Retryer { |
| 98 |
return gax.OnHTTPCodes(gax.Backoff{ |
| 99 |
Initial: 1000 * time.Millisecond, |
| 100 |
Max: 10000 * time.Millisecond, |
| 101 |
Multiplier: 1.30, |
| 102 |
}, |
| 103 |
http.StatusServiceUnavailable) |
| 104 |
}), |
| 105 |
}, |
| 106 |
ListCssProducts: []gax.CallOption{ |
| 107 |
gax.WithTimeout(60000 * time.Millisecond), |
| 108 |
gax.WithRetry(func() gax.Retryer { |
| 109 |
return gax.OnHTTPCodes(gax.Backoff{ |
| 110 |
Initial: 1000 * time.Millisecond, |
| 111 |
Max: 10000 * time.Millisecond, |
| 112 |
Multiplier: 1.30, |
| 113 |
}, |
| 114 |
http.StatusServiceUnavailable) |
| 115 |
}), |
| 116 |
}, |
| 117 |
} |
| 118 |
} |
| 119 |
|
| 120 |
// internalCssProductsClient is an interface that defines the methods available from CSS API. |
| 121 |
type internalCssProductsClient interface { |
| 122 |
Close() error |
| 123 |
setGoogleClientInfo(...string) |
| 124 |
Connection() *grpc.ClientConn |
| 125 |
GetCssProduct(context.Context, *csspb.GetCssProductRequest, ...gax.CallOption) (*csspb.CssProduct, error) |
| 126 |
ListCssProducts(context.Context, *csspb.ListCssProductsRequest, ...gax.CallOption) *CssProductIterator |
| 127 |
} |
| 128 |
|
| 129 |
// CssProductsClient is a client for interacting with CSS API. |
| 130 |
// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. |
| 131 |
// |
| 132 |
// Service for doing get and list on Css Products(a.k.a Aggregate Offers |
| 133 |
// internally). |
| 134 |
type CssProductsClient struct { |
| 135 |
// The internal transport-dependent client. |
| 136 |
internalClient internalCssProductsClient |
| 137 |
|
| 138 |
// The call options for this service. |
| 139 |
CallOptions *CssProductsCallOptions |
| 140 |
} |
| 141 |
|
| 142 |
// Wrapper methods routed to the internal client. |
| 143 |
|
| 144 |
// Close closes the connection to the API service. The user should invoke this when |
| 145 |
// the client is no longer required. |
| 146 |
func (c *CssProductsClient) Close() error { |
| 147 |
return c.internalClient.Close() |
| 148 |
} |
| 149 |
|
| 150 |
// setGoogleClientInfo sets the name and version of the application in |
| 151 |
// the `x-goog-api-client` header passed on each request. Intended for |
| 152 |
// use by Google-written clients. |
| 153 |
func (c *CssProductsClient) setGoogleClientInfo(keyval ...string) { |
| 154 |
c.internalClient.setGoogleClientInfo(keyval...) |
| 155 |
} |
| 156 |
|
| 157 |
// Connection returns a connection to the API service. |
| 158 |
// |
| 159 |
// Deprecated: Connections are now pooled so this method does not always |
| 160 |
// return the same resource. |
| 161 |
func (c *CssProductsClient) Connection() *grpc.ClientConn { |
| 162 |
return c.internalClient.Connection() |
| 163 |
} |
| 164 |
|
| 165 |
// GetCssProduct retrieves the processed CSS Product from your CSS Center account. After |
| 166 |
// inserting, updating, or deleting a product input, it may take several |
| 167 |
// minutes before the updated final product can be retrieved. |
| 168 |
func (c *CssProductsClient) GetCssProduct(ctx context.Context, req *csspb.GetCssProductRequest, opts ...gax.CallOption) (*csspb.CssProduct, error) { |
| 169 |
return c.internalClient.GetCssProduct(ctx, req, opts...) |
| 170 |
} |
| 171 |
|
| 172 |
// ListCssProducts lists the processed CSS Products in your CSS Center account. The response |
| 173 |
// might contain fewer items than specified by pageSize. Rely on pageToken to |
| 174 |
// determine if there are more items to be requested. |
| 175 |
// |
| 176 |
// After inserting, updating, or deleting a CSS product input, it may |
| 177 |
// take several minutes before the updated processed CSS product can be |
| 178 |
// retrieved. |
| 179 |
func (c *CssProductsClient) ListCssProducts(ctx context.Context, req *csspb.ListCssProductsRequest, opts ...gax.CallOption) *CssProductIterator { |
| 180 |
return c.internalClient.ListCssProducts(ctx, req, opts...) |
| 181 |
} |
| 182 |
|
| 183 |
// cssProductsGRPCClient is a client for interacting with CSS API over gRPC transport. |
| 184 |
// |
| 185 |
// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. |
| 186 |
type cssProductsGRPCClient struct { |
| 187 |
// Connection pool of gRPC connections to the service. |
| 188 |
connPool gtransport.ConnPool |
| 189 |
|
| 190 |
// Points back to the CallOptions field of the containing CssProductsClient |
| 191 |
CallOptions **CssProductsCallOptions |
| 192 |
|
| 193 |
// The gRPC API client. |
| 194 |
cssProductsClient csspb.CssProductsServiceClient |
| 195 |
|
| 196 |
// The x-goog-* metadata to be sent with each request. |
| 197 |
xGoogHeaders []string |
| 198 |
|
| 199 |
logger *slog.Logger |
| 200 |
} |
| 201 |
|
| 202 |
// NewCssProductsClient creates a new css products service client based on gRPC. |
| 203 |
// The returned client must be Closed when it is done being used to clean up its underlying connections. |
| 204 |
// |
| 205 |
// Service for doing get and list on Css Products(a.k.a Aggregate Offers |
| 206 |
// internally). |
| 207 |
func NewCssProductsClient(ctx context.Context, opts ...option.ClientOption) (*CssProductsClient, error) { |
| 208 |
clientOpts := defaultCssProductsGRPCClientOptions() |
| 209 |
if newCssProductsClientHook != nil { |
| 210 |
hookOpts, err := newCssProductsClientHook(ctx, clientHookParams{}) |
| 211 |
if err != nil { |
| 212 |
return nil, err |
| 213 |
} |
| 214 |
clientOpts = append(clientOpts, hookOpts...) |
| 215 |
} |
| 216 |
|
| 217 |
connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...) |
| 218 |
if err != nil { |
| 219 |
return nil, err |
| 220 |
} |
| 221 |
client := CssProductsClient{CallOptions: defaultCssProductsCallOptions()} |
| 222 |
|
| 223 |
c := &cssProductsGRPCClient{ |
| 224 |
connPool: connPool, |
| 225 |
cssProductsClient: csspb.NewCssProductsServiceClient(connPool), |
| 226 |
CallOptions: &client.CallOptions, |
| 227 |
logger: internaloption.GetLogger(opts), |
| 228 |
} |
| 229 |
c.setGoogleClientInfo() |
| 230 |
|
| 231 |
client.internalClient = c |
| 232 |
|
| 233 |
return &client, nil |
| 234 |
} |
| 235 |
|
| 236 |
// Connection returns a connection to the API service. |
| 237 |
// |
| 238 |
// Deprecated: Connections are now pooled so this method does not always |
| 239 |
// return the same resource. |
| 240 |
func (c *cssProductsGRPCClient) Connection() *grpc.ClientConn { |
| 241 |
return c.connPool.Conn() |
| 242 |
} |
| 243 |
|
| 244 |
// setGoogleClientInfo sets the name and version of the application in |
| 245 |
// the `x-goog-api-client` header passed on each request. Intended for |
| 246 |
// use by Google-written clients. |
| 247 |
func (c *cssProductsGRPCClient) setGoogleClientInfo(keyval ...string) { |
| 248 |
kv := append([]string{"gl-go", gax.GoVersion}, keyval...) |
| 249 |
kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "grpc", grpc.Version, "pb", protoVersion) |
| 250 |
c.xGoogHeaders = []string{ |
| 251 |
"x-goog-api-client", gax.XGoogHeader(kv...), |
| 252 |
} |
| 253 |
} |
| 254 |
|
| 255 |
// Close closes the connection to the API service. The user should invoke this when |
| 256 |
// the client is no longer required. |
| 257 |
func (c *cssProductsGRPCClient) Close() error { |
| 258 |
return c.connPool.Close() |
| 259 |
} |
| 260 |
|
| 261 |
// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. |
| 262 |
type cssProductsRESTClient struct { |
| 263 |
// The http endpoint to connect to. |
| 264 |
endpoint string |
| 265 |
|
| 266 |
// The http client. |
| 267 |
httpClient *http.Client |
| 268 |
|
| 269 |
// The x-goog-* headers to be sent with each request. |
| 270 |
xGoogHeaders []string |
| 271 |
|
| 272 |
// Points back to the CallOptions field of the containing CssProductsClient |
| 273 |
CallOptions **CssProductsCallOptions |
| 274 |
|
| 275 |
logger *slog.Logger |
| 276 |
} |
| 277 |
|
| 278 |
// NewCssProductsRESTClient creates a new css products service rest client. |
| 279 |
// |
| 280 |
// Service for doing get and list on Css Products(a.k.a Aggregate Offers |
| 281 |
// internally). |
| 282 |
func NewCssProductsRESTClient(ctx context.Context, opts ...option.ClientOption) (*CssProductsClient, error) { |
| 283 |
clientOpts := append(defaultCssProductsRESTClientOptions(), opts...) |
| 284 |
httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...) |
| 285 |
if err != nil { |
| 286 |
return nil, err |
| 287 |
} |
| 288 |
|
| 289 |
callOpts := defaultCssProductsRESTCallOptions() |
| 290 |
c := &cssProductsRESTClient{ |
| 291 |
endpoint: endpoint, |
| 292 |
httpClient: httpClient, |
| 293 |
CallOptions: &callOpts, |
| 294 |
logger: internaloption.GetLogger(opts), |
| 295 |
} |
| 296 |
c.setGoogleClientInfo() |
| 297 |
|
| 298 |
return &CssProductsClient{internalClient: c, CallOptions: callOpts}, nil |
| 299 |
} |
| 300 |
|
| 301 |
func defaultCssProductsRESTClientOptions() []option.ClientOption { |
| 302 |
return []option.ClientOption{ |
| 303 |
internaloption.WithDefaultEndpoint("https://css.googleapis.com"), |
| 304 |
internaloption.WithDefaultEndpointTemplate("https://css.UNIVERSE_DOMAIN"), |
| 305 |
internaloption.WithDefaultMTLSEndpoint("https://css.mtls.googleapis.com"), |
| 306 |
internaloption.WithDefaultUniverseDomain("googleapis.com"), |
| 307 |
internaloption.WithDefaultAudience("https://css.googleapis.com/"), |
| 308 |
internaloption.WithDefaultScopes(DefaultAuthScopes()...), |
| 309 |
internaloption.EnableNewAuthLibrary(), |
| 310 |
} |
| 311 |
} |
| 312 |
|
| 313 |
// setGoogleClientInfo sets the name and version of the application in |
| 314 |
// the `x-goog-api-client` header passed on each request. Intended for |
| 315 |
// use by Google-written clients. |
| 316 |
func (c *cssProductsRESTClient) setGoogleClientInfo(keyval ...string) { |
| 317 |
kv := append([]string{"gl-go", gax.GoVersion}, keyval...) |
| 318 |
kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "rest", "UNKNOWN", "pb", protoVersion) |
| 319 |
c.xGoogHeaders = []string{ |
| 320 |
"x-goog-api-client", gax.XGoogHeader(kv...), |
| 321 |
} |
| 322 |
} |
| 323 |
|
| 324 |
// Close closes the connection to the API service. The user should invoke this when |
| 325 |
// the client is no longer required. |
| 326 |
func (c *cssProductsRESTClient) Close() error { |
| 327 |
// Replace httpClient with nil to force cleanup. |
| 328 |
c.httpClient = nil |
| 329 |
return nil |
| 330 |
} |
| 331 |
|
| 332 |
// Connection returns a connection to the API service. |
| 333 |
// |
| 334 |
// Deprecated: This method always returns nil. |
| 335 |
func (c *cssProductsRESTClient) Connection() *grpc.ClientConn { |
| 336 |
return nil |
| 337 |
} |
| 338 |
func (c *cssProductsGRPCClient) GetCssProduct(ctx context.Context, req *csspb.GetCssProductRequest, opts ...gax.CallOption) (*csspb.CssProduct, error) { |
| 339 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| 340 |
|
| 341 |
hds = append(c.xGoogHeaders, hds...) |
| 342 |
ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) |
| 343 |
opts = append((*c.CallOptions).GetCssProduct[0:len((*c.CallOptions).GetCssProduct):len((*c.CallOptions).GetCssProduct)], opts...) |
| 344 |
var resp *csspb.CssProduct |
| 345 |
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 346 |
var err error |
| 347 |
resp, err = executeRPC(ctx, c.cssProductsClient.GetCssProduct, req, settings.GRPC, c.logger, "GetCssProduct") |
| 348 |
return err |
| 349 |
}, opts...) |
| 350 |
if err != nil { |
| 351 |
return nil, err |
| 352 |
} |
| 353 |
return resp, nil |
| 354 |
} |
| 355 |
|
| 356 |
func (c *cssProductsGRPCClient) ListCssProducts(ctx context.Context, req *csspb.ListCssProductsRequest, opts ...gax.CallOption) *CssProductIterator { |
| 357 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))} |
| 358 |
|
| 359 |
hds = append(c.xGoogHeaders, hds...) |
| 360 |
ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) |
| 361 |
opts = append((*c.CallOptions).ListCssProducts[0:len((*c.CallOptions).ListCssProducts):len((*c.CallOptions).ListCssProducts)], opts...) |
| 362 |
it := &CssProductIterator{} |
| 363 |
req = proto.Clone(req).(*csspb.ListCssProductsRequest) |
| 364 |
it.InternalFetch = func(pageSize int, pageToken string) ([]*csspb.CssProduct, string, error) { |
| 365 |
resp := &csspb.ListCssProductsResponse{} |
| 366 |
if pageToken != "" { |
| 367 |
req.PageToken = pageToken |
| 368 |
} |
| 369 |
if pageSize > math.MaxInt32 { |
| 370 |
req.PageSize = math.MaxInt32 |
| 371 |
} else if pageSize != 0 { |
| 372 |
req.PageSize = int32(pageSize) |
| 373 |
} |
| 374 |
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 375 |
var err error |
| 376 |
resp, err = executeRPC(ctx, c.cssProductsClient.ListCssProducts, req, settings.GRPC, c.logger, "ListCssProducts") |
| 377 |
return err |
| 378 |
}, opts...) |
| 379 |
if err != nil { |
| 380 |
return nil, "", err |
| 381 |
} |
| 382 |
|
| 383 |
it.Response = resp |
| 384 |
return resp.GetCssProducts(), resp.GetNextPageToken(), nil |
| 385 |
} |
| 386 |
fetch := func(pageSize int, pageToken string) (string, error) { |
| 387 |
items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) |
| 388 |
if err != nil { |
| 389 |
return "", err |
| 390 |
} |
| 391 |
it.items = append(it.items, items...) |
| 392 |
return nextPageToken, nil |
| 393 |
} |
| 394 |
|
| 395 |
it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) |
| 396 |
it.pageInfo.MaxSize = int(req.GetPageSize()) |
| 397 |
it.pageInfo.Token = req.GetPageToken() |
| 398 |
|
| 399 |
return it |
| 400 |
} |
| 401 |
|
| 402 |
// GetCssProduct retrieves the processed CSS Product from your CSS Center account. After |
| 403 |
// inserting, updating, or deleting a product input, it may take several |
| 404 |
// minutes before the updated final product can be retrieved. |
| 405 |
func (c *cssProductsRESTClient) GetCssProduct(ctx context.Context, req *csspb.GetCssProductRequest, opts ...gax.CallOption) (*csspb.CssProduct, error) { |
| 406 |
baseUrl, err := url.Parse(c.endpoint) |
| 407 |
if err != nil { |
| 408 |
return nil, err |
| 409 |
} |
| 410 |
baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetName()) |
| 411 |
|
| 412 |
params := url.Values{} |
| 413 |
params.Add("$alt", "json;enum-encoding=int") |
| 414 |
|
| 415 |
baseUrl.RawQuery = params.Encode() |
| 416 |
|
| 417 |
// Build HTTP headers from client and context metadata. |
| 418 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| 419 |
|
| 420 |
hds = append(c.xGoogHeaders, hds...) |
| 421 |
hds = append(hds, "Content-Type", "application/json") |
| 422 |
headers := gax.BuildHeaders(ctx, hds...) |
| 423 |
opts = append((*c.CallOptions).GetCssProduct[0:len((*c.CallOptions).GetCssProduct):len((*c.CallOptions).GetCssProduct)], opts...) |
| 424 |
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| 425 |
resp := &csspb.CssProduct{} |
| 426 |
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 427 |
if settings.Path != "" { |
| 428 |
baseUrl.Path = settings.Path |
| 429 |
} |
| 430 |
httpReq, err := http.NewRequest("GET", baseUrl.String(), nil) |
| 431 |
if err != nil { |
| 432 |
return err |
| 433 |
} |
| 434 |
httpReq = httpReq.WithContext(ctx) |
| 435 |
httpReq.Header = headers |
| 436 |
|
| 437 |
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetCssProduct") |
| 438 |
if err != nil { |
| 439 |
return err |
| 440 |
} |
| 441 |
|
| 442 |
if err := unm.Unmarshal(buf, resp); err != nil { |
| 443 |
return err |
| 444 |
} |
| 445 |
|
| 446 |
return nil |
| 447 |
}, opts...) |
| 448 |
if e != nil { |
| 449 |
return nil, e |
| 450 |
} |
| 451 |
return resp, nil |
| 452 |
} |
| 453 |
|
| 454 |
// ListCssProducts lists the processed CSS Products in your CSS Center account. The response |
| 455 |
// might contain fewer items than specified by pageSize. Rely on pageToken to |
| 456 |
// determine if there are more items to be requested. |
| 457 |
// |
| 458 |
// After inserting, updating, or deleting a CSS product input, it may |
| 459 |
// take several minutes before the updated processed CSS product can be |
| 460 |
// retrieved. |
| 461 |
func (c *cssProductsRESTClient) ListCssProducts(ctx context.Context, req *csspb.ListCssProductsRequest, opts ...gax.CallOption) *CssProductIterator { |
| 462 |
it := &CssProductIterator{} |
| 463 |
req = proto.Clone(req).(*csspb.ListCssProductsRequest) |
| 464 |
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| 465 |
it.InternalFetch = func(pageSize int, pageToken string) ([]*csspb.CssProduct, string, error) { |
| 466 |
resp := &csspb.ListCssProductsResponse{} |
| 467 |
if pageToken != "" { |
| 468 |
req.PageToken = pageToken |
| 469 |
} |
| 470 |
if pageSize > math.MaxInt32 { |
| 471 |
req.PageSize = math.MaxInt32 |
| 472 |
} else if pageSize != 0 { |
| 473 |
req.PageSize = int32(pageSize) |
| 474 |
} |
| 475 |
baseUrl, err := url.Parse(c.endpoint) |
| 476 |
if err != nil { |
| 477 |
return nil, "", err |
| 478 |
} |
| 479 |
baseUrl.Path += fmt.Sprintf("/v1/%v/cssProducts", req.GetParent()) |
| 480 |
|
| 481 |
params := url.Values{} |
| 482 |
params.Add("$alt", "json;enum-encoding=int") |
| 483 |
if req.GetPageSize() != 0 { |
| 484 |
params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize())) |
| 485 |
} |
| 486 |
if req.GetPageToken() != "" { |
| 487 |
params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) |
| 488 |
} |
| 489 |
|
| 490 |
baseUrl.RawQuery = params.Encode() |
| 491 |
|
| 492 |
// Build HTTP headers from client and context metadata. |
| 493 |
hds := append(c.xGoogHeaders, "Content-Type", "application/json") |
| 494 |
headers := gax.BuildHeaders(ctx, hds...) |
| 495 |
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 496 |
if settings.Path != "" { |
| 497 |
baseUrl.Path = settings.Path |
| 498 |
} |
| 499 |
httpReq, err := http.NewRequest("GET", baseUrl.String(), nil) |
| 500 |
if err != nil { |
| 501 |
return err |
| 502 |
} |
| 503 |
httpReq.Header = headers |
| 504 |
|
| 505 |
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "ListCssProducts") |
| 506 |
if err != nil { |
| 507 |
return err |
| 508 |
} |
| 509 |
if err := unm.Unmarshal(buf, resp); err != nil { |
| 510 |
return err |
| 511 |
} |
| 512 |
|
| 513 |
return nil |
| 514 |
}, opts...) |
| 515 |
if e != nil { |
| 516 |
return nil, "", e |
| 517 |
} |
| 518 |
it.Response = resp |
| 519 |
return resp.GetCssProducts(), resp.GetNextPageToken(), nil |
| 520 |
} |
| 521 |
|
| 522 |
fetch := func(pageSize int, pageToken string) (string, error) { |
| 523 |
items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) |
| 524 |
if err != nil { |
| 525 |
return "", err |
| 526 |
} |
| 527 |
it.items = append(it.items, items...) |
| 528 |
return nextPageToken, nil |
| 529 |
} |
| 530 |
|
| 531 |
it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) |
| 532 |
it.pageInfo.MaxSize = int(req.GetPageSize()) |
| 533 |
it.pageInfo.Token = req.GetPageToken() |
| 534 |
|
| 535 |
return it |
| 536 |
} |