| 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 productstudio |
| 18 |
|
| 19 |
import ( |
| 20 |
"bytes" |
| 21 |
"context" |
| 22 |
"fmt" |
| 23 |
"log/slog" |
| 24 |
"math" |
| 25 |
"net/http" |
| 26 |
"net/url" |
| 27 |
"time" |
| 28 |
|
| 29 |
productstudiopb "cloud.google.com/go/shopping/merchant/productstudio/apiv1alpha/productstudiopb" |
| 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/grpc/codes" |
| 37 |
"google.golang.org/protobuf/encoding/protojson" |
| 38 |
) |
| 39 |
|
| 40 |
var newImageClientHook clientHook |
| 41 |
|
| 42 |
// ImageCallOptions contains the retry settings for each method of ImageClient. |
| 43 |
type ImageCallOptions struct { |
| 44 |
GenerateProductImageBackground []gax.CallOption |
| 45 |
RemoveProductImageBackground []gax.CallOption |
| 46 |
UpscaleProductImage []gax.CallOption |
| 47 |
} |
| 48 |
|
| 49 |
func defaultImageGRPCClientOptions() []option.ClientOption { |
| 50 |
return []option.ClientOption{ |
| 51 |
internaloption.WithDefaultEndpoint("merchantapi.googleapis.com:443"), |
| 52 |
internaloption.WithDefaultEndpointTemplate("merchantapi.UNIVERSE_DOMAIN:443"), |
| 53 |
internaloption.WithDefaultMTLSEndpoint("merchantapi.mtls.googleapis.com:443"), |
| 54 |
internaloption.WithDefaultUniverseDomain("googleapis.com"), |
| 55 |
internaloption.WithDefaultAudience("https://merchantapi.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 defaultImageCallOptions() *ImageCallOptions { |
| 65 |
return &ImageCallOptions{ |
| 66 |
GenerateProductImageBackground: []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 |
RemoveProductImageBackground: []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 |
UpscaleProductImage: []gax.CallOption{ |
| 91 |
gax.WithTimeout(60000 * time.Millisecond), |
| 92 |
gax.WithRetry(func() gax.Retryer { |
| 93 |
return gax.OnCodes([]codes.Code{ |
| 94 |
codes.Unavailable, |
| 95 |
}, gax.Backoff{ |
| 96 |
Initial: 1000 * time.Millisecond, |
| 97 |
Max: 10000 * time.Millisecond, |
| 98 |
Multiplier: 1.30, |
| 99 |
}) |
| 100 |
}), |
| 101 |
}, |
| 102 |
} |
| 103 |
} |
| 104 |
|
| 105 |
func defaultImageRESTCallOptions() *ImageCallOptions { |
| 106 |
return &ImageCallOptions{ |
| 107 |
GenerateProductImageBackground: []gax.CallOption{ |
| 108 |
gax.WithTimeout(60000 * time.Millisecond), |
| 109 |
gax.WithRetry(func() gax.Retryer { |
| 110 |
return gax.OnHTTPCodes(gax.Backoff{ |
| 111 |
Initial: 1000 * time.Millisecond, |
| 112 |
Max: 10000 * time.Millisecond, |
| 113 |
Multiplier: 1.30, |
| 114 |
}, |
| 115 |
http.StatusServiceUnavailable) |
| 116 |
}), |
| 117 |
}, |
| 118 |
RemoveProductImageBackground: []gax.CallOption{ |
| 119 |
gax.WithTimeout(60000 * time.Millisecond), |
| 120 |
gax.WithRetry(func() gax.Retryer { |
| 121 |
return gax.OnHTTPCodes(gax.Backoff{ |
| 122 |
Initial: 1000 * time.Millisecond, |
| 123 |
Max: 10000 * time.Millisecond, |
| 124 |
Multiplier: 1.30, |
| 125 |
}, |
| 126 |
http.StatusServiceUnavailable) |
| 127 |
}), |
| 128 |
}, |
| 129 |
UpscaleProductImage: []gax.CallOption{ |
| 130 |
gax.WithTimeout(60000 * time.Millisecond), |
| 131 |
gax.WithRetry(func() gax.Retryer { |
| 132 |
return gax.OnHTTPCodes(gax.Backoff{ |
| 133 |
Initial: 1000 * time.Millisecond, |
| 134 |
Max: 10000 * time.Millisecond, |
| 135 |
Multiplier: 1.30, |
| 136 |
}, |
| 137 |
http.StatusServiceUnavailable) |
| 138 |
}), |
| 139 |
}, |
| 140 |
} |
| 141 |
} |
| 142 |
|
| 143 |
// internalImageClient is an interface that defines the methods available from Merchant API. |
| 144 |
type internalImageClient interface { |
| 145 |
Close() error |
| 146 |
setGoogleClientInfo(...string) |
| 147 |
Connection() *grpc.ClientConn |
| 148 |
GenerateProductImageBackground(context.Context, *productstudiopb.GenerateProductImageBackgroundRequest, ...gax.CallOption) (*productstudiopb.GenerateProductImageBackgroundResponse, error) |
| 149 |
RemoveProductImageBackground(context.Context, *productstudiopb.RemoveProductImageBackgroundRequest, ...gax.CallOption) (*productstudiopb.RemoveProductImageBackgroundResponse, error) |
| 150 |
UpscaleProductImage(context.Context, *productstudiopb.UpscaleProductImageRequest, ...gax.CallOption) (*productstudiopb.UpscaleProductImageResponse, error) |
| 151 |
} |
| 152 |
|
| 153 |
// ImageClient is a client for interacting with Merchant API. |
| 154 |
// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. |
| 155 |
// |
| 156 |
// Service that exposes Generative AI (GenAI) endpoints for creating and |
| 157 |
// enhancing product image content. |
| 158 |
type ImageClient struct { |
| 159 |
// The internal transport-dependent client. |
| 160 |
internalClient internalImageClient |
| 161 |
|
| 162 |
// The call options for this service. |
| 163 |
CallOptions *ImageCallOptions |
| 164 |
} |
| 165 |
|
| 166 |
// Wrapper methods routed to the internal client. |
| 167 |
|
| 168 |
// Close closes the connection to the API service. The user should invoke this when |
| 169 |
// the client is no longer required. |
| 170 |
func (c *ImageClient) Close() error { |
| 171 |
return c.internalClient.Close() |
| 172 |
} |
| 173 |
|
| 174 |
// setGoogleClientInfo sets the name and version of the application in |
| 175 |
// the `x-goog-api-client` header passed on each request. Intended for |
| 176 |
// use by Google-written clients. |
| 177 |
func (c *ImageClient) setGoogleClientInfo(keyval ...string) { |
| 178 |
c.internalClient.setGoogleClientInfo(keyval...) |
| 179 |
} |
| 180 |
|
| 181 |
// Connection returns a connection to the API service. |
| 182 |
// |
| 183 |
// Deprecated: Connections are now pooled so this method does not always |
| 184 |
// return the same resource. |
| 185 |
func (c *ImageClient) Connection() *grpc.ClientConn { |
| 186 |
return c.internalClient.Connection() |
| 187 |
} |
| 188 |
|
| 189 |
// GenerateProductImageBackground generateProductImageBackground generates a new image where the background |
| 190 |
// of the original image is replaced by an AI generated scene based on |
| 191 |
// provided product information and a text prompt. |
| 192 |
func (c *ImageClient) GenerateProductImageBackground(ctx context.Context, req *productstudiopb.GenerateProductImageBackgroundRequest, opts ...gax.CallOption) (*productstudiopb.GenerateProductImageBackgroundResponse, error) { |
| 193 |
return c.internalClient.GenerateProductImageBackground(ctx, req, opts...) |
| 194 |
} |
| 195 |
|
| 196 |
// RemoveProductImageBackground removeProductImageBackground generates a new image where the background of |
| 197 |
// the original image is removed. |
| 198 |
func (c *ImageClient) RemoveProductImageBackground(ctx context.Context, req *productstudiopb.RemoveProductImageBackgroundRequest, opts ...gax.CallOption) (*productstudiopb.RemoveProductImageBackgroundResponse, error) { |
| 199 |
return c.internalClient.RemoveProductImageBackground(ctx, req, opts...) |
| 200 |
} |
| 201 |
|
| 202 |
// UpscaleProductImage upscaleProductImage generates a new image where the resolution of the |
| 203 |
// original image is enhanced. |
| 204 |
func (c *ImageClient) UpscaleProductImage(ctx context.Context, req *productstudiopb.UpscaleProductImageRequest, opts ...gax.CallOption) (*productstudiopb.UpscaleProductImageResponse, error) { |
| 205 |
return c.internalClient.UpscaleProductImage(ctx, req, opts...) |
| 206 |
} |
| 207 |
|
| 208 |
// imageGRPCClient is a client for interacting with Merchant API over gRPC transport. |
| 209 |
// |
| 210 |
// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. |
| 211 |
type imageGRPCClient struct { |
| 212 |
// Connection pool of gRPC connections to the service. |
| 213 |
connPool gtransport.ConnPool |
| 214 |
|
| 215 |
// Points back to the CallOptions field of the containing ImageClient |
| 216 |
CallOptions **ImageCallOptions |
| 217 |
|
| 218 |
// The gRPC API client. |
| 219 |
imageClient productstudiopb.ImageServiceClient |
| 220 |
|
| 221 |
// The x-goog-* metadata to be sent with each request. |
| 222 |
xGoogHeaders []string |
| 223 |
|
| 224 |
logger *slog.Logger |
| 225 |
} |
| 226 |
|
| 227 |
// NewImageClient creates a new image service client based on gRPC. |
| 228 |
// The returned client must be Closed when it is done being used to clean up its underlying connections. |
| 229 |
// |
| 230 |
// Service that exposes Generative AI (GenAI) endpoints for creating and |
| 231 |
// enhancing product image content. |
| 232 |
func NewImageClient(ctx context.Context, opts ...option.ClientOption) (*ImageClient, error) { |
| 233 |
clientOpts := defaultImageGRPCClientOptions() |
| 234 |
if newImageClientHook != nil { |
| 235 |
hookOpts, err := newImageClientHook(ctx, clientHookParams{}) |
| 236 |
if err != nil { |
| 237 |
return nil, err |
| 238 |
} |
| 239 |
clientOpts = append(clientOpts, hookOpts...) |
| 240 |
} |
| 241 |
|
| 242 |
connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...) |
| 243 |
if err != nil { |
| 244 |
return nil, err |
| 245 |
} |
| 246 |
client := ImageClient{CallOptions: defaultImageCallOptions()} |
| 247 |
|
| 248 |
c := &imageGRPCClient{ |
| 249 |
connPool: connPool, |
| 250 |
imageClient: productstudiopb.NewImageServiceClient(connPool), |
| 251 |
CallOptions: &client.CallOptions, |
| 252 |
logger: internaloption.GetLogger(opts), |
| 253 |
} |
| 254 |
c.setGoogleClientInfo() |
| 255 |
|
| 256 |
client.internalClient = c |
| 257 |
|
| 258 |
return &client, nil |
| 259 |
} |
| 260 |
|
| 261 |
// Connection returns a connection to the API service. |
| 262 |
// |
| 263 |
// Deprecated: Connections are now pooled so this method does not always |
| 264 |
// return the same resource. |
| 265 |
func (c *imageGRPCClient) Connection() *grpc.ClientConn { |
| 266 |
return c.connPool.Conn() |
| 267 |
} |
| 268 |
|
| 269 |
// setGoogleClientInfo sets the name and version of the application in |
| 270 |
// the `x-goog-api-client` header passed on each request. Intended for |
| 271 |
// use by Google-written clients. |
| 272 |
func (c *imageGRPCClient) setGoogleClientInfo(keyval ...string) { |
| 273 |
kv := append([]string{"gl-go", gax.GoVersion}, keyval...) |
| 274 |
kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "grpc", grpc.Version, "pb", protoVersion) |
| 275 |
c.xGoogHeaders = []string{ |
| 276 |
"x-goog-api-client", gax.XGoogHeader(kv...), |
| 277 |
} |
| 278 |
} |
| 279 |
|
| 280 |
// Close closes the connection to the API service. The user should invoke this when |
| 281 |
// the client is no longer required. |
| 282 |
func (c *imageGRPCClient) Close() error { |
| 283 |
return c.connPool.Close() |
| 284 |
} |
| 285 |
|
| 286 |
// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. |
| 287 |
type imageRESTClient struct { |
| 288 |
// The http endpoint to connect to. |
| 289 |
endpoint string |
| 290 |
|
| 291 |
// The http client. |
| 292 |
httpClient *http.Client |
| 293 |
|
| 294 |
// The x-goog-* headers to be sent with each request. |
| 295 |
xGoogHeaders []string |
| 296 |
|
| 297 |
// Points back to the CallOptions field of the containing ImageClient |
| 298 |
CallOptions **ImageCallOptions |
| 299 |
|
| 300 |
logger *slog.Logger |
| 301 |
} |
| 302 |
|
| 303 |
// NewImageRESTClient creates a new image service rest client. |
| 304 |
// |
| 305 |
// Service that exposes Generative AI (GenAI) endpoints for creating and |
| 306 |
// enhancing product image content. |
| 307 |
func NewImageRESTClient(ctx context.Context, opts ...option.ClientOption) (*ImageClient, error) { |
| 308 |
clientOpts := append(defaultImageRESTClientOptions(), opts...) |
| 309 |
httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...) |
| 310 |
if err != nil { |
| 311 |
return nil, err |
| 312 |
} |
| 313 |
|
| 314 |
callOpts := defaultImageRESTCallOptions() |
| 315 |
c := &imageRESTClient{ |
| 316 |
endpoint: endpoint, |
| 317 |
httpClient: httpClient, |
| 318 |
CallOptions: &callOpts, |
| 319 |
logger: internaloption.GetLogger(opts), |
| 320 |
} |
| 321 |
c.setGoogleClientInfo() |
| 322 |
|
| 323 |
return &ImageClient{internalClient: c, CallOptions: callOpts}, nil |
| 324 |
} |
| 325 |
|
| 326 |
func defaultImageRESTClientOptions() []option.ClientOption { |
| 327 |
return []option.ClientOption{ |
| 328 |
internaloption.WithDefaultEndpoint("https://merchantapi.googleapis.com"), |
| 329 |
internaloption.WithDefaultEndpointTemplate("https://merchantapi.UNIVERSE_DOMAIN"), |
| 330 |
internaloption.WithDefaultMTLSEndpoint("https://merchantapi.mtls.googleapis.com"), |
| 331 |
internaloption.WithDefaultUniverseDomain("googleapis.com"), |
| 332 |
internaloption.WithDefaultAudience("https://merchantapi.googleapis.com/"), |
| 333 |
internaloption.WithDefaultScopes(DefaultAuthScopes()...), |
| 334 |
internaloption.EnableNewAuthLibrary(), |
| 335 |
} |
| 336 |
} |
| 337 |
|
| 338 |
// setGoogleClientInfo sets the name and version of the application in |
| 339 |
// the `x-goog-api-client` header passed on each request. Intended for |
| 340 |
// use by Google-written clients. |
| 341 |
func (c *imageRESTClient) setGoogleClientInfo(keyval ...string) { |
| 342 |
kv := append([]string{"gl-go", gax.GoVersion}, keyval...) |
| 343 |
kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "rest", "UNKNOWN", "pb", protoVersion) |
| 344 |
c.xGoogHeaders = []string{ |
| 345 |
"x-goog-api-client", gax.XGoogHeader(kv...), |
| 346 |
} |
| 347 |
} |
| 348 |
|
| 349 |
// Close closes the connection to the API service. The user should invoke this when |
| 350 |
// the client is no longer required. |
| 351 |
func (c *imageRESTClient) Close() error { |
| 352 |
// Replace httpClient with nil to force cleanup. |
| 353 |
c.httpClient = nil |
| 354 |
return nil |
| 355 |
} |
| 356 |
|
| 357 |
// Connection returns a connection to the API service. |
| 358 |
// |
| 359 |
// Deprecated: This method always returns nil. |
| 360 |
func (c *imageRESTClient) Connection() *grpc.ClientConn { |
| 361 |
return nil |
| 362 |
} |
| 363 |
func (c *imageGRPCClient) GenerateProductImageBackground(ctx context.Context, req *productstudiopb.GenerateProductImageBackgroundRequest, opts ...gax.CallOption) (*productstudiopb.GenerateProductImageBackgroundResponse, error) { |
| 364 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| 365 |
|
| 366 |
hds = append(c.xGoogHeaders, hds...) |
| 367 |
ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) |
| 368 |
opts = append((*c.CallOptions).GenerateProductImageBackground[0:len((*c.CallOptions).GenerateProductImageBackground):len((*c.CallOptions).GenerateProductImageBackground)], opts...) |
| 369 |
var resp *productstudiopb.GenerateProductImageBackgroundResponse |
| 370 |
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 371 |
var err error |
| 372 |
resp, err = executeRPC(ctx, c.imageClient.GenerateProductImageBackground, req, settings.GRPC, c.logger, "GenerateProductImageBackground") |
| 373 |
return err |
| 374 |
}, opts...) |
| 375 |
if err != nil { |
| 376 |
return nil, err |
| 377 |
} |
| 378 |
return resp, nil |
| 379 |
} |
| 380 |
|
| 381 |
func (c *imageGRPCClient) RemoveProductImageBackground(ctx context.Context, req *productstudiopb.RemoveProductImageBackgroundRequest, opts ...gax.CallOption) (*productstudiopb.RemoveProductImageBackgroundResponse, error) { |
| 382 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| 383 |
|
| 384 |
hds = append(c.xGoogHeaders, hds...) |
| 385 |
ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) |
| 386 |
opts = append((*c.CallOptions).RemoveProductImageBackground[0:len((*c.CallOptions).RemoveProductImageBackground):len((*c.CallOptions).RemoveProductImageBackground)], opts...) |
| 387 |
var resp *productstudiopb.RemoveProductImageBackgroundResponse |
| 388 |
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 389 |
var err error |
| 390 |
resp, err = executeRPC(ctx, c.imageClient.RemoveProductImageBackground, req, settings.GRPC, c.logger, "RemoveProductImageBackground") |
| 391 |
return err |
| 392 |
}, opts...) |
| 393 |
if err != nil { |
| 394 |
return nil, err |
| 395 |
} |
| 396 |
return resp, nil |
| 397 |
} |
| 398 |
|
| 399 |
func (c *imageGRPCClient) UpscaleProductImage(ctx context.Context, req *productstudiopb.UpscaleProductImageRequest, opts ...gax.CallOption) (*productstudiopb.UpscaleProductImageResponse, error) { |
| 400 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| 401 |
|
| 402 |
hds = append(c.xGoogHeaders, hds...) |
| 403 |
ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) |
| 404 |
opts = append((*c.CallOptions).UpscaleProductImage[0:len((*c.CallOptions).UpscaleProductImage):len((*c.CallOptions).UpscaleProductImage)], opts...) |
| 405 |
var resp *productstudiopb.UpscaleProductImageResponse |
| 406 |
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 407 |
var err error |
| 408 |
resp, err = executeRPC(ctx, c.imageClient.UpscaleProductImage, req, settings.GRPC, c.logger, "UpscaleProductImage") |
| 409 |
return err |
| 410 |
}, opts...) |
| 411 |
if err != nil { |
| 412 |
return nil, err |
| 413 |
} |
| 414 |
return resp, nil |
| 415 |
} |
| 416 |
|
| 417 |
// GenerateProductImageBackground generateProductImageBackground generates a new image where the background |
| 418 |
// of the original image is replaced by an AI generated scene based on |
| 419 |
// provided product information and a text prompt. |
| 420 |
func (c *imageRESTClient) GenerateProductImageBackground(ctx context.Context, req *productstudiopb.GenerateProductImageBackgroundRequest, opts ...gax.CallOption) (*productstudiopb.GenerateProductImageBackgroundResponse, error) { |
| 421 |
m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true} |
| 422 |
jsonReq, err := m.Marshal(req) |
| 423 |
if err != nil { |
| 424 |
return nil, err |
| 425 |
} |
| 426 |
|
| 427 |
baseUrl, err := url.Parse(c.endpoint) |
| 428 |
if err != nil { |
| 429 |
return nil, err |
| 430 |
} |
| 431 |
baseUrl.Path += fmt.Sprintf("/productstudio/v1alpha/%v/generatedImages:generateProductImageBackground", req.GetName()) |
| 432 |
|
| 433 |
params := url.Values{} |
| 434 |
params.Add("$alt", "json;enum-encoding=int") |
| 435 |
|
| 436 |
baseUrl.RawQuery = params.Encode() |
| 437 |
|
| 438 |
// Build HTTP headers from client and context metadata. |
| 439 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| 440 |
|
| 441 |
hds = append(c.xGoogHeaders, hds...) |
| 442 |
hds = append(hds, "Content-Type", "application/json") |
| 443 |
headers := gax.BuildHeaders(ctx, hds...) |
| 444 |
opts = append((*c.CallOptions).GenerateProductImageBackground[0:len((*c.CallOptions).GenerateProductImageBackground):len((*c.CallOptions).GenerateProductImageBackground)], opts...) |
| 445 |
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| 446 |
resp := &productstudiopb.GenerateProductImageBackgroundResponse{} |
| 447 |
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 448 |
if settings.Path != "" { |
| 449 |
baseUrl.Path = settings.Path |
| 450 |
} |
| 451 |
httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) |
| 452 |
if err != nil { |
| 453 |
return err |
| 454 |
} |
| 455 |
httpReq = httpReq.WithContext(ctx) |
| 456 |
httpReq.Header = headers |
| 457 |
|
| 458 |
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "GenerateProductImageBackground") |
| 459 |
if err != nil { |
| 460 |
return err |
| 461 |
} |
| 462 |
|
| 463 |
if err := unm.Unmarshal(buf, resp); err != nil { |
| 464 |
return err |
| 465 |
} |
| 466 |
|
| 467 |
return nil |
| 468 |
}, opts...) |
| 469 |
if e != nil { |
| 470 |
return nil, e |
| 471 |
} |
| 472 |
return resp, nil |
| 473 |
} |
| 474 |
|
| 475 |
// RemoveProductImageBackground removeProductImageBackground generates a new image where the background of |
| 476 |
// the original image is removed. |
| 477 |
func (c *imageRESTClient) RemoveProductImageBackground(ctx context.Context, req *productstudiopb.RemoveProductImageBackgroundRequest, opts ...gax.CallOption) (*productstudiopb.RemoveProductImageBackgroundResponse, error) { |
| 478 |
m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true} |
| 479 |
jsonReq, err := m.Marshal(req) |
| 480 |
if err != nil { |
| 481 |
return nil, err |
| 482 |
} |
| 483 |
|
| 484 |
baseUrl, err := url.Parse(c.endpoint) |
| 485 |
if err != nil { |
| 486 |
return nil, err |
| 487 |
} |
| 488 |
baseUrl.Path += fmt.Sprintf("/productstudio/v1alpha/%v/generatedImages:removeProductImageBackground", req.GetName()) |
| 489 |
|
| 490 |
params := url.Values{} |
| 491 |
params.Add("$alt", "json;enum-encoding=int") |
| 492 |
|
| 493 |
baseUrl.RawQuery = params.Encode() |
| 494 |
|
| 495 |
// Build HTTP headers from client and context metadata. |
| 496 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| 497 |
|
| 498 |
hds = append(c.xGoogHeaders, hds...) |
| 499 |
hds = append(hds, "Content-Type", "application/json") |
| 500 |
headers := gax.BuildHeaders(ctx, hds...) |
| 501 |
opts = append((*c.CallOptions).RemoveProductImageBackground[0:len((*c.CallOptions).RemoveProductImageBackground):len((*c.CallOptions).RemoveProductImageBackground)], opts...) |
| 502 |
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| 503 |
resp := &productstudiopb.RemoveProductImageBackgroundResponse{} |
| 504 |
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 505 |
if settings.Path != "" { |
| 506 |
baseUrl.Path = settings.Path |
| 507 |
} |
| 508 |
httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) |
| 509 |
if err != nil { |
| 510 |
return err |
| 511 |
} |
| 512 |
httpReq = httpReq.WithContext(ctx) |
| 513 |
httpReq.Header = headers |
| 514 |
|
| 515 |
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "RemoveProductImageBackground") |
| 516 |
if err != nil { |
| 517 |
return err |
| 518 |
} |
| 519 |
|
| 520 |
if err := unm.Unmarshal(buf, resp); err != nil { |
| 521 |
return err |
| 522 |
} |
| 523 |
|
| 524 |
return nil |
| 525 |
}, opts...) |
| 526 |
if e != nil { |
| 527 |
return nil, e |
| 528 |
} |
| 529 |
return resp, nil |
| 530 |
} |
| 531 |
|
| 532 |
// UpscaleProductImage upscaleProductImage generates a new image where the resolution of the |
| 533 |
// original image is enhanced. |
| 534 |
func (c *imageRESTClient) UpscaleProductImage(ctx context.Context, req *productstudiopb.UpscaleProductImageRequest, opts ...gax.CallOption) (*productstudiopb.UpscaleProductImageResponse, error) { |
| 535 |
m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true} |
| 536 |
jsonReq, err := m.Marshal(req) |
| 537 |
if err != nil { |
| 538 |
return nil, err |
| 539 |
} |
| 540 |
|
| 541 |
baseUrl, err := url.Parse(c.endpoint) |
| 542 |
if err != nil { |
| 543 |
return nil, err |
| 544 |
} |
| 545 |
baseUrl.Path += fmt.Sprintf("/productstudio/v1alpha/%v/generatedImages:upscaleProductImage", req.GetName()) |
| 546 |
|
| 547 |
params := url.Values{} |
| 548 |
params.Add("$alt", "json;enum-encoding=int") |
| 549 |
|
| 550 |
baseUrl.RawQuery = params.Encode() |
| 551 |
|
| 552 |
// Build HTTP headers from client and context metadata. |
| 553 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| 554 |
|
| 555 |
hds = append(c.xGoogHeaders, hds...) |
| 556 |
hds = append(hds, "Content-Type", "application/json") |
| 557 |
headers := gax.BuildHeaders(ctx, hds...) |
| 558 |
opts = append((*c.CallOptions).UpscaleProductImage[0:len((*c.CallOptions).UpscaleProductImage):len((*c.CallOptions).UpscaleProductImage)], opts...) |
| 559 |
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| 560 |
resp := &productstudiopb.UpscaleProductImageResponse{} |
| 561 |
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 562 |
if settings.Path != "" { |
| 563 |
baseUrl.Path = settings.Path |
| 564 |
} |
| 565 |
httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) |
| 566 |
if err != nil { |
| 567 |
return err |
| 568 |
} |
| 569 |
httpReq = httpReq.WithContext(ctx) |
| 570 |
httpReq.Header = headers |
| 571 |
|
| 572 |
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "UpscaleProductImage") |
| 573 |
if err != nil { |
| 574 |
return err |
| 575 |
} |
| 576 |
|
| 577 |
if err := unm.Unmarshal(buf, resp); err != nil { |
| 578 |
return err |
| 579 |
} |
| 580 |
|
| 581 |
return nil |
| 582 |
}, opts...) |
| 583 |
if e != nil { |
| 584 |
return nil, e |
| 585 |
} |
| 586 |
return resp, nil |
| 587 |
} |