| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package accounts |
| 18 |
|
| 19 |
import ( |
| 20 |
"bytes" |
| 21 |
"context" |
| 22 |
"fmt" |
| 23 |
"log/slog" |
| 24 |
"math" |
| 25 |
"net/http" |
| 26 |
"net/url" |
| 27 |
"time" |
| 28 |
|
| 29 |
accountspb "cloud.google.com/go/shopping/merchant/accounts/apiv1beta/accountspb" |
| 30 |
gax "github.com/googleapis/gax-go/v2" |
| 31 |
"google.golang.org/api/iterator" |
| 32 |
"google.golang.org/api/option" |
| 33 |
"google.golang.org/api/option/internaloption" |
| 34 |
gtransport "google.golang.org/api/transport/grpc" |
| 35 |
httptransport "google.golang.org/api/transport/http" |
| 36 |
"google.golang.org/grpc" |
| 37 |
"google.golang.org/grpc/codes" |
| 38 |
"google.golang.org/protobuf/encoding/protojson" |
| 39 |
"google.golang.org/protobuf/proto" |
| 40 |
) |
| 41 |
|
| 42 |
var newAccountTaxClientHook clientHook |
| 43 |
|
| 44 |
|
| 45 |
type AccountTaxCallOptions struct { |
| 46 |
GetAccountTax []gax.CallOption |
| 47 |
ListAccountTax []gax.CallOption |
| 48 |
UpdateAccountTax []gax.CallOption |
| 49 |
} |
| 50 |
|
| 51 |
func defaultAccountTaxGRPCClientOptions() []option.ClientOption { |
| 52 |
return []option.ClientOption{ |
| 53 |
internaloption.WithDefaultEndpoint("merchantapi.googleapis.com:443"), |
| 54 |
internaloption.WithDefaultEndpointTemplate("merchantapi.UNIVERSE_DOMAIN:443"), |
| 55 |
internaloption.WithDefaultMTLSEndpoint("merchantapi.mtls.googleapis.com:443"), |
| 56 |
internaloption.WithDefaultUniverseDomain("googleapis.com"), |
| 57 |
internaloption.WithDefaultAudience("https://merchantapi.googleapis.com/"), |
| 58 |
internaloption.WithDefaultScopes(DefaultAuthScopes()...), |
| 59 |
internaloption.EnableJwtWithScope(), |
| 60 |
internaloption.EnableNewAuthLibrary(), |
| 61 |
option.WithGRPCDialOption(grpc.WithDefaultCallOptions( |
| 62 |
grpc.MaxCallRecvMsgSize(math.MaxInt32))), |
| 63 |
} |
| 64 |
} |
| 65 |
|
| 66 |
func defaultAccountTaxCallOptions() *AccountTaxCallOptions { |
| 67 |
return &AccountTaxCallOptions{ |
| 68 |
GetAccountTax: []gax.CallOption{ |
| 69 |
gax.WithTimeout(60000 * time.Millisecond), |
| 70 |
gax.WithRetry(func() gax.Retryer { |
| 71 |
return gax.OnCodes([]codes.Code{ |
| 72 |
codes.Unavailable, |
| 73 |
}, gax.Backoff{ |
| 74 |
Initial: 1000 * time.Millisecond, |
| 75 |
Max: 10000 * time.Millisecond, |
| 76 |
Multiplier: 1.30, |
| 77 |
}) |
| 78 |
}), |
| 79 |
}, |
| 80 |
ListAccountTax: []gax.CallOption{ |
| 81 |
gax.WithTimeout(60000 * time.Millisecond), |
| 82 |
gax.WithRetry(func() gax.Retryer { |
| 83 |
return gax.OnCodes([]codes.Code{ |
| 84 |
codes.Unavailable, |
| 85 |
}, gax.Backoff{ |
| 86 |
Initial: 1000 * time.Millisecond, |
| 87 |
Max: 10000 * time.Millisecond, |
| 88 |
Multiplier: 1.30, |
| 89 |
}) |
| 90 |
}), |
| 91 |
}, |
| 92 |
UpdateAccountTax: []gax.CallOption{ |
| 93 |
gax.WithTimeout(60000 * time.Millisecond), |
| 94 |
gax.WithRetry(func() gax.Retryer { |
| 95 |
return gax.OnCodes([]codes.Code{ |
| 96 |
codes.Unavailable, |
| 97 |
}, gax.Backoff{ |
| 98 |
Initial: 1000 * time.Millisecond, |
| 99 |
Max: 10000 * time.Millisecond, |
| 100 |
Multiplier: 1.30, |
| 101 |
}) |
| 102 |
}), |
| 103 |
}, |
| 104 |
} |
| 105 |
} |
| 106 |
|
| 107 |
func defaultAccountTaxRESTCallOptions() *AccountTaxCallOptions { |
| 108 |
return &AccountTaxCallOptions{ |
| 109 |
GetAccountTax: []gax.CallOption{ |
| 110 |
gax.WithTimeout(60000 * time.Millisecond), |
| 111 |
gax.WithRetry(func() gax.Retryer { |
| 112 |
return gax.OnHTTPCodes(gax.Backoff{ |
| 113 |
Initial: 1000 * time.Millisecond, |
| 114 |
Max: 10000 * time.Millisecond, |
| 115 |
Multiplier: 1.30, |
| 116 |
}, |
| 117 |
http.StatusServiceUnavailable) |
| 118 |
}), |
| 119 |
}, |
| 120 |
ListAccountTax: []gax.CallOption{ |
| 121 |
gax.WithTimeout(60000 * time.Millisecond), |
| 122 |
gax.WithRetry(func() gax.Retryer { |
| 123 |
return gax.OnHTTPCodes(gax.Backoff{ |
| 124 |
Initial: 1000 * time.Millisecond, |
| 125 |
Max: 10000 * time.Millisecond, |
| 126 |
Multiplier: 1.30, |
| 127 |
}, |
| 128 |
http.StatusServiceUnavailable) |
| 129 |
}), |
| 130 |
}, |
| 131 |
UpdateAccountTax: []gax.CallOption{ |
| 132 |
gax.WithTimeout(60000 * time.Millisecond), |
| 133 |
gax.WithRetry(func() gax.Retryer { |
| 134 |
return gax.OnHTTPCodes(gax.Backoff{ |
| 135 |
Initial: 1000 * time.Millisecond, |
| 136 |
Max: 10000 * time.Millisecond, |
| 137 |
Multiplier: 1.30, |
| 138 |
}, |
| 139 |
http.StatusServiceUnavailable) |
| 140 |
}), |
| 141 |
}, |
| 142 |
} |
| 143 |
} |
| 144 |
|
| 145 |
|
| 146 |
type internalAccountTaxClient interface { |
| 147 |
Close() error |
| 148 |
setGoogleClientInfo(...string) |
| 149 |
Connection() *grpc.ClientConn |
| 150 |
GetAccountTax(context.Context, *accountspb.GetAccountTaxRequest, ...gax.CallOption) (*accountspb.AccountTax, error) |
| 151 |
ListAccountTax(context.Context, *accountspb.ListAccountTaxRequest, ...gax.CallOption) *AccountTaxIterator |
| 152 |
UpdateAccountTax(context.Context, *accountspb.UpdateAccountTaxRequest, ...gax.CallOption) (*accountspb.AccountTax, error) |
| 153 |
} |
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
type AccountTaxClient struct { |
| 164 |
|
| 165 |
internalClient internalAccountTaxClient |
| 166 |
|
| 167 |
|
| 168 |
CallOptions *AccountTaxCallOptions |
| 169 |
} |
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
func (c *AccountTaxClient) Close() error { |
| 176 |
return c.internalClient.Close() |
| 177 |
} |
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
func (c *AccountTaxClient) setGoogleClientInfo(keyval ...string) { |
| 183 |
c.internalClient.setGoogleClientInfo(keyval...) |
| 184 |
} |
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
func (c *AccountTaxClient) Connection() *grpc.ClientConn { |
| 191 |
return c.internalClient.Connection() |
| 192 |
} |
| 193 |
|
| 194 |
|
| 195 |
func (c *AccountTaxClient) GetAccountTax(ctx context.Context, req *accountspb.GetAccountTaxRequest, opts ...gax.CallOption) (*accountspb.AccountTax, error) { |
| 196 |
return c.internalClient.GetAccountTax(ctx, req, opts...) |
| 197 |
} |
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
ll |
| 202 |
|
| 203 |
func (c *AccountTaxClient) ListAccountTax(ctx context.Context, req *accountspb.ListAccountTaxRequest, opts ...gax.CallOption) *AccountTaxIterator { |
| 204 |
return c.internalClient.ListAccountTax(ctx, req, opts...) |
| 205 |
} |
| 206 |
|
| 207 |
|
| 208 |
func (c *AccountTaxClient) UpdateAccountTax(ctx context.Context, req *accountspb.UpdateAccountTaxRequest, opts ...gax.CallOption) (*accountspb.AccountTax, error) { |
| 209 |
return c.internalClient.UpdateAccountTax(ctx, req, opts...) |
| 210 |
} |
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
type accountTaxGRPCClient struct { |
| 216 |
|
| 217 |
connPool gtransport.ConnPool |
| 218 |
|
| 219 |
|
| 220 |
CallOptions **AccountTaxCallOptions |
| 221 |
|
| 222 |
|
| 223 |
accountTaxClient accountspb.AccountTaxServiceClient |
| 224 |
|
| 225 |
|
| 226 |
xGoogHeaders []string |
| 227 |
|
| 228 |
logger *slog.Logger |
| 229 |
} |
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
func NewAccountTaxClient(ctx context.Context, opts ...option.ClientOption) (*AccountTaxClient, error) { |
| 240 |
clientOpts := defaultAccountTaxGRPCClientOptions() |
| 241 |
if newAccountTaxClientHook != nil { |
| 242 |
hookOpts, err := newAccountTaxClientHook(ctx, clientHookParams{}) |
| 243 |
if err != nil { |
| 244 |
return nil, err |
| 245 |
} |
| 246 |
clientOpts = append(clientOpts, hookOpts...) |
| 247 |
} |
| 248 |
|
| 249 |
connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...) |
| 250 |
if err != nil { |
| 251 |
return nil, err |
| 252 |
} |
| 253 |
client := AccountTaxClient{CallOptions: defaultAccountTaxCallOptions()} |
| 254 |
|
| 255 |
c := &accountTaxGRPCClient{ |
| 256 |
connPool: connPool, |
| 257 |
accountTaxClient: accountspb.NewAccountTaxServiceClient(connPool), |
| 258 |
CallOptions: &client.CallOptions, |
| 259 |
logger: internaloption.GetLogger(opts), |
| 260 |
} |
| 261 |
c.setGoogleClientInfo() |
| 262 |
|
| 263 |
client.internalClient = c |
| 264 |
|
| 265 |
return &client, nil |
| 266 |
} |
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
|
| 272 |
func (c *accountTaxGRPCClient) Connection() *grpc.ClientConn { |
| 273 |
return c.connPool.Conn() |
| 274 |
} |
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
|
| 279 |
func (c *accountTaxGRPCClient) setGoogleClientInfo(keyval ...string) { |
| 280 |
kv := append([]string{"gl-go", gax.GoVersion}, keyval...) |
| 281 |
kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "grpc", grpc.Version, "pb", protoVersion) |
| 282 |
c.xGoogHeaders = []string{ |
| 283 |
"x-goog-api-client", gax.XGoogHeader(kv...), |
| 284 |
} |
| 285 |
} |
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
func (c *accountTaxGRPCClient) Close() error { |
| 290 |
return c.connPool.Close() |
| 291 |
} |
| 292 |
|
| 293 |
|
| 294 |
type accountTaxRESTClient struct { |
| 295 |
|
| 296 |
endpoint string |
| 297 |
|
| 298 |
|
| 299 |
httpClient *http.Client |
| 300 |
|
| 301 |
|
| 302 |
xGoogHeaders []string |
| 303 |
|
| 304 |
|
| 305 |
CallOptions **AccountTaxCallOptions |
| 306 |
|
| 307 |
logger *slog.Logger |
| 308 |
} |
| 309 |
|
| 310 |
|
| 311 |
|
| 312 |
|
| 313 |
|
| 314 |
|
| 315 |
|
| 316 |
|
| 317 |
func NewAccountTaxRESTClient(ctx context.Context, opts ...option.ClientOption) (*AccountTaxClient, error) { |
| 318 |
clientOpts := append(defaultAccountTaxRESTClientOptions(), opts...) |
| 319 |
httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...) |
| 320 |
if err != nil { |
| 321 |
return nil, err |
| 322 |
} |
| 323 |
|
| 324 |
callOpts := defaultAccountTaxRESTCallOptions() |
| 325 |
c := &accountTaxRESTClient{ |
| 326 |
endpoint: endpoint, |
| 327 |
httpClient: httpClient, |
| 328 |
CallOptions: &callOpts, |
| 329 |
logger: internaloption.GetLogger(opts), |
| 330 |
} |
| 331 |
c.setGoogleClientInfo() |
| 332 |
|
| 333 |
return &AccountTaxClient{internalClient: c, CallOptions: callOpts}, nil |
| 334 |
} |
| 335 |
|
| 336 |
func defaultAccountTaxRESTClientOptions() []option.ClientOption { |
| 337 |
return []option.ClientOption{ |
| 338 |
internaloption.WithDefaultEndpoint("https://merchantapi.googleapis.com"), |
| 339 |
internaloption.WithDefaultEndpointTemplate("https://merchantapi.UNIVERSE_DOMAIN"), |
| 340 |
internaloption.WithDefaultMTLSEndpoint("https://merchantapi.mtls.googleapis.com"), |
| 341 |
internaloption.WithDefaultUniverseDomain("googleapis.com"), |
| 342 |
internaloption.WithDefaultAudience("https://merchantapi.googleapis.com/"), |
| 343 |
internaloption.WithDefaultScopes(DefaultAuthScopes()...), |
| 344 |
internaloption.EnableNewAuthLibrary(), |
| 345 |
} |
| 346 |
} |
| 347 |
|
| 348 |
|
| 349 |
|
| 350 |
|
| 351 |
func (c *accountTaxRESTClient) setGoogleClientInfo(keyval ...string) { |
| 352 |
kv := append([]string{"gl-go", gax.GoVersion}, keyval...) |
| 353 |
kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "rest", "UNKNOWN", "pb", protoVersion) |
| 354 |
c.xGoogHeaders = []string{ |
| 355 |
"x-goog-api-client", gax.XGoogHeader(kv...), |
| 356 |
} |
| 357 |
} |
| 358 |
|
| 359 |
|
| 360 |
|
| 361 |
func (c *accountTaxRESTClient) Close() error { |
| 362 |
|
| 363 |
c.httpClient = nil |
| 364 |
return nil |
| 365 |
} |
| 366 |
|
| 367 |
|
| 368 |
|
| 369 |
|
| 370 |
func (c *accountTaxRESTClient) Connection() *grpc.ClientConn { |
| 371 |
return nil |
| 372 |
} |
| 373 |
func (c *accountTaxGRPCClient) GetAccountTax(ctx context.Context, req *accountspb.GetAccountTaxRequest, opts ...gax.CallOption) (*accountspb.AccountTax, error) { |
| 374 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| 375 |
|
| 376 |
hds = append(c.xGoogHeaders, hds...) |
| 377 |
ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) |
| 378 |
opts = append((*c.CallOptions).GetAccountTax[0:len((*c.CallOptions).GetAccountTax):len((*c.CallOptions).GetAccountTax)], opts...) |
| 379 |
var resp *accountspb.AccountTax |
| 380 |
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 381 |
var err error |
| 382 |
resp, err = executeRPC(ctx, c.accountTaxClient.GetAccountTax, req, settings.GRPC, c.logger, "GetAccountTax") |
| 383 |
return err |
| 384 |
}, opts...) |
| 385 |
if err != nil { |
| 386 |
return nil, err |
| 387 |
} |
| 388 |
return resp, nil |
| 389 |
} |
| 390 |
|
| 391 |
func (c *accountTaxGRPCClient) ListAccountTax(ctx context.Context, req *accountspb.ListAccountTaxRequest, opts ...gax.CallOption) *AccountTaxIterator { |
| 392 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))} |
| 393 |
|
| 394 |
hds = append(c.xGoogHeaders, hds...) |
| 395 |
ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) |
| 396 |
opts = append((*c.CallOptions).ListAccountTax[0:len((*c.CallOptions).ListAccountTax):len((*c.CallOptions).ListAccountTax)], opts...) |
| 397 |
it := &AccountTaxIterator{} |
| 398 |
req = proto.Clone(req).(*accountspb.ListAccountTaxRequest) |
| 399 |
it.InternalFetch = func(pageSize int, pageToken string) ([]*accountspb.AccountTax, string, error) { |
| 400 |
resp := &accountspb.ListAccountTaxResponse{} |
| 401 |
if pageToken != "" { |
| 402 |
req.PageToken = pageToken |
| 403 |
} |
| 404 |
if pageSize > math.MaxInt32 { |
| 405 |
req.PageSize = math.MaxInt32 |
| 406 |
} else if pageSize != 0 { |
| 407 |
req.PageSize = int32(pageSize) |
| 408 |
} |
| 409 |
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 410 |
var err error |
| 411 |
resp, err = executeRPC(ctx, c.accountTaxClient.ListAccountTax, req, settings.GRPC, c.logger, "ListAccountTax") |
| 412 |
return err |
| 413 |
}, opts...) |
| 414 |
if err != nil { |
| 415 |
return nil, "", err |
| 416 |
} |
| 417 |
|
| 418 |
it.Response = resp |
| 419 |
return resp.GetAccountTaxes(), resp.GetNextPageToken(), nil |
| 420 |
} |
| 421 |
fetch := func(pageSize int, pageToken string) (string, error) { |
| 422 |
items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) |
| 423 |
if err != nil { |
| 424 |
return "", err |
| 425 |
} |
| 426 |
it.items = append(it.items, items...) |
| 427 |
return nextPageToken, nil |
| 428 |
} |
| 429 |
|
| 430 |
it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) |
| 431 |
it.pageInfo.MaxSize = int(req.GetPageSize()) |
| 432 |
it.pageInfo.Token = req.GetPageToken() |
| 433 |
|
| 434 |
return it |
| 435 |
} |
| 436 |
|
| 437 |
func (c *accountTaxGRPCClient) UpdateAccountTax(ctx context.Context, req *accountspb.UpdateAccountTaxRequest, opts ...gax.CallOption) (*accountspb.AccountTax, error) { |
| 438 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "account_tax.name", url.QueryEscape(req.GetAccountTax().GetName()))} |
| 439 |
|
| 440 |
hds = append(c.xGoogHeaders, hds...) |
| 441 |
ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) |
| 442 |
opts = append((*c.CallOptions).UpdateAccountTax[0:len((*c.CallOptions).UpdateAccountTax):len((*c.CallOptions).UpdateAccountTax)], opts...) |
| 443 |
var resp *accountspb.AccountTax |
| 444 |
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 445 |
var err error |
| 446 |
resp, err = executeRPC(ctx, c.accountTaxClient.UpdateAccountTax, req, settings.GRPC, c.logger, "UpdateAccountTax") |
| 447 |
return err |
| 448 |
}, opts...) |
| 449 |
if err != nil { |
| 450 |
return nil, err |
| 451 |
} |
| 452 |
return resp, nil |
| 453 |
} |
| 454 |
|
| 455 |
|
| 456 |
func (c *accountTaxRESTClient) GetAccountTax(ctx context.Context, req *accountspb.GetAccountTaxRequest, opts ...gax.CallOption) (*accountspb.AccountTax, error) { |
| 457 |
baseUrl, err := url.Parse(c.endpoint) |
| 458 |
if err != nil { |
| 459 |
return nil, err |
| 460 |
} |
| 461 |
baseUrl.Path += fmt.Sprintf("/accounts/v1beta/%v", req.GetName()) |
| 462 |
|
| 463 |
params := url.Values{} |
| 464 |
params.Add("$alt", "json;enum-encoding=int") |
| 465 |
|
| 466 |
baseUrl.RawQuery = params.Encode() |
| 467 |
|
| 468 |
|
| 469 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| 470 |
|
| 471 |
hds = append(c.xGoogHeaders, hds...) |
| 472 |
hds = append(hds, "Content-Type", "application/json") |
| 473 |
headers := gax.BuildHeaders(ctx, hds...) |
| 474 |
opts = append((*c.CallOptions).GetAccountTax[0:len((*c.CallOptions).GetAccountTax):len((*c.CallOptions).GetAccountTax)], opts...) |
| 475 |
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| 476 |
resp := &accountspb.AccountTax{} |
| 477 |
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 478 |
if settings.Path != "" { |
| 479 |
baseUrl.Path = settings.Path |
| 480 |
} |
| 481 |
httpReq, err := http.NewRequest("GET", baseUrl.String(), nil) |
| 482 |
if err != nil { |
| 483 |
return err |
| 484 |
} |
| 485 |
httpReq = httpReq.WithContext(ctx) |
| 486 |
httpReq.Header = headers |
| 487 |
|
| 488 |
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetAccountTax") |
| 489 |
if err != nil { |
| 490 |
return err |
| 491 |
} |
| 492 |
|
| 493 |
if err := unm.Unmarshal(buf, resp); err != nil { |
| 494 |
return err |
| 495 |
} |
| 496 |
|
| 497 |
return nil |
| 498 |
}, opts...) |
| 499 |
if e != nil { |
| 500 |
return nil, e |
| 501 |
} |
| 502 |
return resp, nil |
| 503 |
} |
| 504 |
|
| 505 |
|
| 506 |
|
| 507 |
ll |
| 508 |
|
| 509 |
func (c *accountTaxRESTClient) ListAccountTax(ctx context.Context, req *accountspb.ListAccountTaxRequest, opts ...gax.CallOption) *AccountTaxIterator { |
| 510 |
it := &AccountTaxIterator{} |
| 511 |
req = proto.Clone(req).(*accountspb.ListAccountTaxRequest) |
| 512 |
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| 513 |
it.InternalFetch = func(pageSize int, pageToken string) ([]*accountspb.AccountTax, string, error) { |
| 514 |
resp := &accountspb.ListAccountTaxResponse{} |
| 515 |
if pageToken != "" { |
| 516 |
req.PageToken = pageToken |
| 517 |
} |
| 518 |
if pageSize > math.MaxInt32 { |
| 519 |
req.PageSize = math.MaxInt32 |
| 520 |
} else if pageSize != 0 { |
| 521 |
req.PageSize = int32(pageSize) |
| 522 |
} |
| 523 |
baseUrl, err := url.Parse(c.endpoint) |
| 524 |
if err != nil { |
| 525 |
return nil, "", err |
| 526 |
} |
| 527 |
baseUrl.Path += fmt.Sprintf("/accounts/v1beta/%v/accounttax", req.GetParent()) |
| 528 |
|
| 529 |
params := url.Values{} |
| 530 |
params.Add("$alt", "json;enum-encoding=int") |
| 531 |
if req.GetPageSize() != 0 { |
| 532 |
params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize())) |
| 533 |
} |
| 534 |
if req.GetPageToken() != "" { |
| 535 |
params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) |
| 536 |
} |
| 537 |
|
| 538 |
baseUrl.RawQuery = params.Encode() |
| 539 |
|
| 540 |
|
| 541 |
hds := append(c.xGoogHeaders, "Content-Type", "application/json") |
| 542 |
headers := gax.BuildHeaders(ctx, hds...) |
| 543 |
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 544 |
if settings.Path != "" { |
| 545 |
baseUrl.Path = settings.Path |
| 546 |
} |
| 547 |
httpReq, err := http.NewRequest("GET", baseUrl.String(), nil) |
| 548 |
if err != nil { |
| 549 |
return err |
| 550 |
} |
| 551 |
httpReq.Header = headers |
| 552 |
|
| 553 |
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "ListAccountTax") |
| 554 |
if err != nil { |
| 555 |
return err |
| 556 |
} |
| 557 |
if err := unm.Unmarshal(buf, resp); err != nil { |
| 558 |
return err |
| 559 |
} |
| 560 |
|
| 561 |
return nil |
| 562 |
}, opts...) |
| 563 |
if e != nil { |
| 564 |
return nil, "", e |
| 565 |
} |
| 566 |
it.Response = resp |
| 567 |
return resp.GetAccountTaxes(), resp.GetNextPageToken(), nil |
| 568 |
} |
| 569 |
|
| 570 |
fetch := func(pageSize int, pageToken string) (string, error) { |
| 571 |
items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) |
| 572 |
if err != nil { |
| 573 |
return "", err |
| 574 |
} |
| 575 |
it.items = append(it.items, items...) |
| 576 |
return nextPageToken, nil |
| 577 |
} |
| 578 |
|
| 579 |
it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) |
| 580 |
it.pageInfo.MaxSize = int(req.GetPageSize()) |
| 581 |
it.pageInfo.Token = req.GetPageToken() |
| 582 |
|
| 583 |
return it |
| 584 |
} |
| 585 |
|
| 586 |
|
| 587 |
func (c *accountTaxRESTClient) UpdateAccountTax(ctx context.Context, req *accountspb.UpdateAccountTaxRequest, opts ...gax.CallOption) (*accountspb.AccountTax, error) { |
| 588 |
m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true} |
| 589 |
body := req.GetAccountTax() |
| 590 |
jsonReq, err := m.Marshal(body) |
| 591 |
if err != nil { |
| 592 |
return nil, err |
| 593 |
} |
| 594 |
|
| 595 |
baseUrl, err := url.Parse(c.endpoint) |
| 596 |
if err != nil { |
| 597 |
return nil, err |
| 598 |
} |
| 599 |
baseUrl.Path += fmt.Sprintf("/accounts/v1beta/%v", req.GetAccountTax().GetName()) |
| 600 |
|
| 601 |
params := url.Values{} |
| 602 |
params.Add("$alt", "json;enum-encoding=int") |
| 603 |
if req.GetUpdateMask() != nil { |
| 604 |
field, err := protojson.Marshal(req.GetUpdateMask()) |
| 605 |
if err != nil { |
| 606 |
return nil, err |
| 607 |
} |
| 608 |
params.Add("updateMask", string(field[1:len(field)-1])) |
| 609 |
} |
| 610 |
|
| 611 |
baseUrl.RawQuery = params.Encode() |
| 612 |
|
| 613 |
|
| 614 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "account_tax.name", url.QueryEscape(req.GetAccountTax().GetName()))} |
| 615 |
|
| 616 |
hds = append(c.xGoogHeaders, hds...) |
| 617 |
hds = append(hds, "Content-Type", "application/json") |
| 618 |
headers := gax.BuildHeaders(ctx, hds...) |
| 619 |
opts = append((*c.CallOptions).UpdateAccountTax[0:len((*c.CallOptions).UpdateAccountTax):len((*c.CallOptions).UpdateAccountTax)], opts...) |
| 620 |
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| 621 |
resp := &accountspb.AccountTax{} |
| 622 |
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 623 |
if settings.Path != "" { |
| 624 |
baseUrl.Path = settings.Path |
| 625 |
} |
| 626 |
httpReq, err := http.NewRequest("PATCH", baseUrl.String(), bytes.NewReader(jsonReq)) |
| 627 |
if err != nil { |
| 628 |
return err |
| 629 |
} |
| 630 |
httpReq = httpReq.WithContext(ctx) |
| 631 |
httpReq.Header = headers |
| 632 |
|
| 633 |
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "UpdateAccountTax") |
| 634 |
if err != nil { |
| 635 |
return err |
| 636 |
} |
| 637 |
|
| 638 |
if err := unm.Unmarshal(buf, resp); err != nil { |
| 639 |
return err |
| 640 |
} |
| 641 |
|
| 642 |
return nil |
| 643 |
}, opts...) |
| 644 |
if e != nil { |
| 645 |
return nil, e |
| 646 |
} |
| 647 |
return resp, nil |
| 648 |
} |