| 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 recaptchaenterprise |
| 18 |
|
| 19 |
import ( |
| 20 |
"bytes" |
| 21 |
"context" |
| 22 |
"fmt" |
| 23 |
"log/slog" |
| 24 |
"math" |
| 25 |
"net/http" |
| 26 |
"net/url" |
| 27 |
"time" |
| 28 |
|
| 29 |
recaptchaenterprisepb "cloud.google.com/go/recaptchaenterprise/v2/apiv1beta1/recaptchaenterprisepb" |
| 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/protobuf/encoding/protojson" |
| 37 |
) |
| 38 |
|
| 39 |
var newRecaptchaEnterpriseServiceV1Beta1ClientHook clientHook |
| 40 |
|
| 41 |
// RecaptchaEnterpriseServiceV1Beta1CallOptions contains the retry settings for each method of RecaptchaEnterpriseServiceV1Beta1Client. |
| 42 |
type RecaptchaEnterpriseServiceV1Beta1CallOptions struct { |
| 43 |
CreateAssessment []gax.CallOption |
| 44 |
AnnotateAssessment []gax.CallOption |
| 45 |
} |
| 46 |
|
| 47 |
func defaultRecaptchaEnterpriseServiceV1Beta1GRPCClientOptions() []option.ClientOption { |
| 48 |
return []option.ClientOption{ |
| 49 |
internaloption.WithDefaultEndpoint("recaptchaenterprise.googleapis.com:443"), |
| 50 |
internaloption.WithDefaultEndpointTemplate("recaptchaenterprise.UNIVERSE_DOMAIN:443"), |
| 51 |
internaloption.WithDefaultMTLSEndpoint("recaptchaenterprise.mtls.googleapis.com:443"), |
| 52 |
internaloption.WithDefaultUniverseDomain("googleapis.com"), |
| 53 |
internaloption.WithDefaultAudience("https://recaptchaenterprise.googleapis.com/"), |
| 54 |
internaloption.WithDefaultScopes(DefaultAuthScopes()...), |
| 55 |
internaloption.EnableJwtWithScope(), |
| 56 |
internaloption.EnableNewAuthLibrary(), |
| 57 |
option.WithGRPCDialOption(grpc.WithDefaultCallOptions( |
| 58 |
grpc.MaxCallRecvMsgSize(math.MaxInt32))), |
| 59 |
} |
| 60 |
} |
| 61 |
|
| 62 |
func defaultRecaptchaEnterpriseServiceV1Beta1CallOptions() *RecaptchaEnterpriseServiceV1Beta1CallOptions { |
| 63 |
return &RecaptchaEnterpriseServiceV1Beta1CallOptions{ |
| 64 |
CreateAssessment: []gax.CallOption{ |
| 65 |
gax.WithTimeout(600000 * time.Millisecond), |
| 66 |
}, |
| 67 |
AnnotateAssessment: []gax.CallOption{ |
| 68 |
gax.WithTimeout(600000 * time.Millisecond), |
| 69 |
}, |
| 70 |
} |
| 71 |
} |
| 72 |
|
| 73 |
func defaultRecaptchaEnterpriseServiceV1Beta1RESTCallOptions() *RecaptchaEnterpriseServiceV1Beta1CallOptions { |
| 74 |
return &RecaptchaEnterpriseServiceV1Beta1CallOptions{ |
| 75 |
CreateAssessment: []gax.CallOption{ |
| 76 |
gax.WithTimeout(600000 * time.Millisecond), |
| 77 |
}, |
| 78 |
AnnotateAssessment: []gax.CallOption{ |
| 79 |
gax.WithTimeout(600000 * time.Millisecond), |
| 80 |
}, |
| 81 |
} |
| 82 |
} |
| 83 |
|
| 84 |
// internalRecaptchaEnterpriseServiceV1Beta1Client is an interface that defines the methods available from reCAPTCHA Enterprise API. |
| 85 |
type internalRecaptchaEnterpriseServiceV1Beta1Client interface { |
| 86 |
Close() error |
| 87 |
setGoogleClientInfo(...string) |
| 88 |
Connection() *grpc.ClientConn |
| 89 |
CreateAssessment(context.Context, *recaptchaenterprisepb.CreateAssessmentRequest, ...gax.CallOption) (*recaptchaenterprisepb.Assessment, error) |
| 90 |
AnnotateAssessment(context.Context, *recaptchaenterprisepb.AnnotateAssessmentRequest, ...gax.CallOption) (*recaptchaenterprisepb.AnnotateAssessmentResponse, error) |
| 91 |
} |
| 92 |
|
| 93 |
// RecaptchaEnterpriseServiceV1Beta1Client is a client for interacting with reCAPTCHA Enterprise API. |
| 94 |
// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. |
| 95 |
// |
| 96 |
// Service to determine the likelihood an event is legitimate. |
| 97 |
type RecaptchaEnterpriseServiceV1Beta1Client struct { |
| 98 |
// The internal transport-dependent client. |
| 99 |
internalClient internalRecaptchaEnterpriseServiceV1Beta1Client |
| 100 |
|
| 101 |
// The call options for this service. |
| 102 |
CallOptions *RecaptchaEnterpriseServiceV1Beta1CallOptions |
| 103 |
} |
| 104 |
|
| 105 |
// Wrapper methods routed to the internal client. |
| 106 |
|
| 107 |
// Close closes the connection to the API service. The user should invoke this when |
| 108 |
// the client is no longer required. |
| 109 |
func (c *RecaptchaEnterpriseServiceV1Beta1Client) Close() error { |
| 110 |
return c.internalClient.Close() |
| 111 |
} |
| 112 |
|
| 113 |
// setGoogleClientInfo sets the name and version of the application in |
| 114 |
// the `x-goog-api-client` header passed on each request. Intended for |
| 115 |
// use by Google-written clients. |
| 116 |
func (c *RecaptchaEnterpriseServiceV1Beta1Client) setGoogleClientInfo(keyval ...string) { |
| 117 |
c.internalClient.setGoogleClientInfo(keyval...) |
| 118 |
} |
| 119 |
|
| 120 |
// Connection returns a connection to the API service. |
| 121 |
// |
| 122 |
// Deprecated: Connections are now pooled so this method does not always |
| 123 |
// return the same resource. |
| 124 |
func (c *RecaptchaEnterpriseServiceV1Beta1Client) Connection() *grpc.ClientConn { |
| 125 |
return c.internalClient.Connection() |
| 126 |
} |
| 127 |
|
| 128 |
// CreateAssessment creates an Assessment of the likelihood an event is legitimate. |
| 129 |
func (c *RecaptchaEnterpriseServiceV1Beta1Client) CreateAssessment(ctx context.Context, req *recaptchaenterprisepb.CreateAssessmentRequest, opts ...gax.CallOption) (*recaptchaenterprisepb.Assessment, error) { |
| 130 |
return c.internalClient.CreateAssessment(ctx, req, opts...) |
| 131 |
} |
| 132 |
|
| 133 |
// AnnotateAssessment annotates a previously created Assessment to provide additional information |
| 134 |
// on whether the event turned out to be authentic or fradulent. |
| 135 |
func (c *RecaptchaEnterpriseServiceV1Beta1Client) AnnotateAssessment(ctx context.Context, req *recaptchaenterprisepb.AnnotateAssessmentRequest, opts ...gax.CallOption) (*recaptchaenterprisepb.AnnotateAssessmentResponse, error) { |
| 136 |
return c.internalClient.AnnotateAssessment(ctx, req, opts...) |
| 137 |
} |
| 138 |
|
| 139 |
// recaptchaEnterpriseServiceV1Beta1GRPCClient is a client for interacting with reCAPTCHA Enterprise API over gRPC transport. |
| 140 |
// |
| 141 |
// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. |
| 142 |
type recaptchaEnterpriseServiceV1Beta1GRPCClient struct { |
| 143 |
// Connection pool of gRPC connections to the service. |
| 144 |
connPool gtransport.ConnPool |
| 145 |
|
| 146 |
// Points back to the CallOptions field of the containing RecaptchaEnterpriseServiceV1Beta1Client |
| 147 |
CallOptions **RecaptchaEnterpriseServiceV1Beta1CallOptions |
| 148 |
|
| 149 |
// The gRPC API client. |
| 150 |
recaptchaEnterpriseServiceV1Beta1Client recaptchaenterprisepb.RecaptchaEnterpriseServiceV1Beta1Client |
| 151 |
|
| 152 |
// The x-goog-* metadata to be sent with each request. |
| 153 |
xGoogHeaders []string |
| 154 |
|
| 155 |
logger *slog.Logger |
| 156 |
} |
| 157 |
|
| 158 |
// NewRecaptchaEnterpriseServiceV1Beta1Client creates a new recaptcha enterprise service v1 beta1 client based on gRPC. |
| 159 |
// The returned client must be Closed when it is done being used to clean up its underlying connections. |
| 160 |
// |
| 161 |
// Service to determine the likelihood an event is legitimate. |
| 162 |
func NewRecaptchaEnterpriseServiceV1Beta1Client(ctx context.Context, opts ...option.ClientOption) (*RecaptchaEnterpriseServiceV1Beta1Client, error) { |
| 163 |
clientOpts := defaultRecaptchaEnterpriseServiceV1Beta1GRPCClientOptions() |
| 164 |
if newRecaptchaEnterpriseServiceV1Beta1ClientHook != nil { |
| 165 |
hookOpts, err := newRecaptchaEnterpriseServiceV1Beta1ClientHook(ctx, clientHookParams{}) |
| 166 |
if err != nil { |
| 167 |
return nil, err |
| 168 |
} |
| 169 |
clientOpts = append(clientOpts, hookOpts...) |
| 170 |
} |
| 171 |
|
| 172 |
connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...) |
| 173 |
if err != nil { |
| 174 |
return nil, err |
| 175 |
} |
| 176 |
client := RecaptchaEnterpriseServiceV1Beta1Client{CallOptions: defaultRecaptchaEnterpriseServiceV1Beta1CallOptions()} |
| 177 |
|
| 178 |
c := &recaptchaEnterpriseServiceV1Beta1GRPCClient{ |
| 179 |
connPool: connPool, |
| 180 |
recaptchaEnterpriseServiceV1Beta1Client: recaptchaenterprisepb.NewRecaptchaEnterpriseServiceV1Beta1Client(connPool), |
| 181 |
CallOptions: &client.CallOptions, |
| 182 |
logger: internaloption.GetLogger(opts), |
| 183 |
} |
| 184 |
c.setGoogleClientInfo() |
| 185 |
|
| 186 |
client.internalClient = c |
| 187 |
|
| 188 |
return &client, nil |
| 189 |
} |
| 190 |
|
| 191 |
// Connection returns a connection to the API service. |
| 192 |
// |
| 193 |
// Deprecated: Connections are now pooled so this method does not always |
| 194 |
// return the same resource. |
| 195 |
func (c *recaptchaEnterpriseServiceV1Beta1GRPCClient) Connection() *grpc.ClientConn { |
| 196 |
return c.connPool.Conn() |
| 197 |
} |
| 198 |
|
| 199 |
// setGoogleClientInfo sets the name and version of the application in |
| 200 |
// the `x-goog-api-client` header passed on each request. Intended for |
| 201 |
// use by Google-written clients. |
| 202 |
func (c *recaptchaEnterpriseServiceV1Beta1GRPCClient) setGoogleClientInfo(keyval ...string) { |
| 203 |
kv := append([]string{"gl-go", gax.GoVersion}, keyval...) |
| 204 |
kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "grpc", grpc.Version, "pb", protoVersion) |
| 205 |
c.xGoogHeaders = []string{ |
| 206 |
"x-goog-api-client", gax.XGoogHeader(kv...), |
| 207 |
} |
| 208 |
} |
| 209 |
|
| 210 |
// Close closes the connection to the API service. The user should invoke this when |
| 211 |
// the client is no longer required. |
| 212 |
func (c *recaptchaEnterpriseServiceV1Beta1GRPCClient) Close() error { |
| 213 |
return c.connPool.Close() |
| 214 |
} |
| 215 |
|
| 216 |
// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. |
| 217 |
type recaptchaEnterpriseServiceV1Beta1RESTClient struct { |
| 218 |
// The http endpoint to connect to. |
| 219 |
endpoint string |
| 220 |
|
| 221 |
// The http client. |
| 222 |
httpClient *http.Client |
| 223 |
|
| 224 |
// The x-goog-* headers to be sent with each request. |
| 225 |
xGoogHeaders []string |
| 226 |
|
| 227 |
// Points back to the CallOptions field of the containing RecaptchaEnterpriseServiceV1Beta1Client |
| 228 |
CallOptions **RecaptchaEnterpriseServiceV1Beta1CallOptions |
| 229 |
|
| 230 |
logger *slog.Logger |
| 231 |
} |
| 232 |
|
| 233 |
// NewRecaptchaEnterpriseServiceV1Beta1RESTClient creates a new recaptcha enterprise service v1 beta1 rest client. |
| 234 |
// |
| 235 |
// Service to determine the likelihood an event is legitimate. |
| 236 |
func NewRecaptchaEnterpriseServiceV1Beta1RESTClient(ctx context.Context, opts ...option.ClientOption) (*RecaptchaEnterpriseServiceV1Beta1Client, error) { |
| 237 |
clientOpts := append(defaultRecaptchaEnterpriseServiceV1Beta1RESTClientOptions(), opts...) |
| 238 |
httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...) |
| 239 |
if err != nil { |
| 240 |
return nil, err |
| 241 |
} |
| 242 |
|
| 243 |
callOpts := defaultRecaptchaEnterpriseServiceV1Beta1RESTCallOptions() |
| 244 |
c := &recaptchaEnterpriseServiceV1Beta1RESTClient{ |
| 245 |
endpoint: endpoint, |
| 246 |
httpClient: httpClient, |
| 247 |
CallOptions: &callOpts, |
| 248 |
logger: internaloption.GetLogger(opts), |
| 249 |
} |
| 250 |
c.setGoogleClientInfo() |
| 251 |
|
| 252 |
return &RecaptchaEnterpriseServiceV1Beta1Client{internalClient: c, CallOptions: callOpts}, nil |
| 253 |
} |
| 254 |
|
| 255 |
func defaultRecaptchaEnterpriseServiceV1Beta1RESTClientOptions() []option.ClientOption { |
| 256 |
return []option.ClientOption{ |
| 257 |
internaloption.WithDefaultEndpoint("https://recaptchaenterprise.googleapis.com"), |
| 258 |
internaloption.WithDefaultEndpointTemplate("https://recaptchaenterprise.UNIVERSE_DOMAIN"), |
| 259 |
internaloption.WithDefaultMTLSEndpoint("https://recaptchaenterprise.mtls.googleapis.com"), |
| 260 |
internaloption.WithDefaultUniverseDomain("googleapis.com"), |
| 261 |
internaloption.WithDefaultAudience("https://recaptchaenterprise.googleapis.com/"), |
| 262 |
internaloption.WithDefaultScopes(DefaultAuthScopes()...), |
| 263 |
internaloption.EnableNewAuthLibrary(), |
| 264 |
} |
| 265 |
} |
| 266 |
|
| 267 |
// setGoogleClientInfo sets the name and version of the application in |
| 268 |
// the `x-goog-api-client` header passed on each request. Intended for |
| 269 |
// use by Google-written clients. |
| 270 |
func (c *recaptchaEnterpriseServiceV1Beta1RESTClient) setGoogleClientInfo(keyval ...string) { |
| 271 |
kv := append([]string{"gl-go", gax.GoVersion}, keyval...) |
| 272 |
kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "rest", "UNKNOWN", "pb", protoVersion) |
| 273 |
c.xGoogHeaders = []string{ |
| 274 |
"x-goog-api-client", gax.XGoogHeader(kv...), |
| 275 |
} |
| 276 |
} |
| 277 |
|
| 278 |
// Close closes the connection to the API service. The user should invoke this when |
| 279 |
// the client is no longer required. |
| 280 |
func (c *recaptchaEnterpriseServiceV1Beta1RESTClient) Close() error { |
| 281 |
// Replace httpClient with nil to force cleanup. |
| 282 |
c.httpClient = nil |
| 283 |
return nil |
| 284 |
} |
| 285 |
|
| 286 |
// Connection returns a connection to the API service. |
| 287 |
// |
| 288 |
// Deprecated: This method always returns nil. |
| 289 |
func (c *recaptchaEnterpriseServiceV1Beta1RESTClient) Connection() *grpc.ClientConn { |
| 290 |
return nil |
| 291 |
} |
| 292 |
func (c *recaptchaEnterpriseServiceV1Beta1GRPCClient) CreateAssessment(ctx context.Context, req *recaptchaenterprisepb.CreateAssessmentRequest, opts ...gax.CallOption) (*recaptchaenterprisepb.Assessment, error) { |
| 293 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))} |
| 294 |
|
| 295 |
hds = append(c.xGoogHeaders, hds...) |
| 296 |
ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) |
| 297 |
opts = append((*c.CallOptions).CreateAssessment[0:len((*c.CallOptions).CreateAssessment):len((*c.CallOptions).CreateAssessment)], opts...) |
| 298 |
var resp *recaptchaenterprisepb.Assessment |
| 299 |
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 300 |
var err error |
| 301 |
resp, err = executeRPC(ctx, c.recaptchaEnterpriseServiceV1Beta1Client.CreateAssessment, req, settings.GRPC, c.logger, "CreateAssessment") |
| 302 |
return err |
| 303 |
}, opts...) |
| 304 |
if err != nil { |
| 305 |
return nil, err |
| 306 |
} |
| 307 |
return resp, nil |
| 308 |
} |
| 309 |
|
| 310 |
func (c *recaptchaEnterpriseServiceV1Beta1GRPCClient) AnnotateAssessment(ctx context.Context, req *recaptchaenterprisepb.AnnotateAssessmentRequest, opts ...gax.CallOption) (*recaptchaenterprisepb.AnnotateAssessmentResponse, 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).AnnotateAssessment[0:len((*c.CallOptions).AnnotateAssessment):len((*c.CallOptions).AnnotateAssessment)], opts...) |
| 316 |
var resp *recaptchaenterprisepb.AnnotateAssessmentResponse |
| 317 |
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 318 |
var err error |
| 319 |
resp, err = executeRPC(ctx, c.recaptchaEnterpriseServiceV1Beta1Client.AnnotateAssessment, req, settings.GRPC, c.logger, "AnnotateAssessment") |
| 320 |
return err |
| 321 |
}, opts...) |
| 322 |
if err != nil { |
| 323 |
return nil, err |
| 324 |
} |
| 325 |
return resp, nil |
| 326 |
} |
| 327 |
|
| 328 |
// CreateAssessment creates an Assessment of the likelihood an event is legitimate. |
| 329 |
func (c *recaptchaEnterpriseServiceV1Beta1RESTClient) CreateAssessment(ctx context.Context, req *recaptchaenterprisepb.CreateAssessmentRequest, opts ...gax.CallOption) (*recaptchaenterprisepb.Assessment, error) { |
| 330 |
m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true} |
| 331 |
body := req.GetAssessment() |
| 332 |
jsonReq, err := m.Marshal(body) |
| 333 |
if err != nil { |
| 334 |
return nil, err |
| 335 |
} |
| 336 |
|
| 337 |
baseUrl, err := url.Parse(c.endpoint) |
| 338 |
if err != nil { |
| 339 |
return nil, err |
| 340 |
} |
| 341 |
baseUrl.Path += fmt.Sprintf("/v1beta1/%v/assessments", req.GetParent()) |
| 342 |
|
| 343 |
params := url.Values{} |
| 344 |
params.Add("$alt", "json;enum-encoding=int") |
| 345 |
|
| 346 |
baseUrl.RawQuery = params.Encode() |
| 347 |
|
| 348 |
// Build HTTP headers from client and context metadata. |
| 349 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))} |
| 350 |
|
| 351 |
hds = append(c.xGoogHeaders, hds...) |
| 352 |
hds = append(hds, "Content-Type", "application/json") |
| 353 |
headers := gax.BuildHeaders(ctx, hds...) |
| 354 |
opts = append((*c.CallOptions).CreateAssessment[0:len((*c.CallOptions).CreateAssessment):len((*c.CallOptions).CreateAssessment)], opts...) |
| 355 |
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| 356 |
resp := &recaptchaenterprisepb.Assessment{} |
| 357 |
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 358 |
if settings.Path != "" { |
| 359 |
baseUrl.Path = settings.Path |
| 360 |
} |
| 361 |
httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) |
| 362 |
if err != nil { |
| 363 |
return err |
| 364 |
} |
| 365 |
httpReq = httpReq.WithContext(ctx) |
| 366 |
httpReq.Header = headers |
| 367 |
|
| 368 |
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "CreateAssessment") |
| 369 |
if err != nil { |
| 370 |
return err |
| 371 |
} |
| 372 |
|
| 373 |
if err := unm.Unmarshal(buf, resp); err != nil { |
| 374 |
return err |
| 375 |
} |
| 376 |
|
| 377 |
return nil |
| 378 |
}, opts...) |
| 379 |
if e != nil { |
| 380 |
return nil, e |
| 381 |
} |
| 382 |
return resp, nil |
| 383 |
} |
| 384 |
|
| 385 |
// AnnotateAssessment annotates a previously created Assessment to provide additional information |
| 386 |
// on whether the event turned out to be authentic or fradulent. |
| 387 |
func (c *recaptchaEnterpriseServiceV1Beta1RESTClient) AnnotateAssessment(ctx context.Context, req *recaptchaenterprisepb.AnnotateAssessmentRequest, opts ...gax.CallOption) (*recaptchaenterprisepb.AnnotateAssessmentResponse, error) { |
| 388 |
m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true} |
| 389 |
jsonReq, err := m.Marshal(req) |
| 390 |
if err != nil { |
| 391 |
return nil, err |
| 392 |
} |
| 393 |
|
| 394 |
baseUrl, err := url.Parse(c.endpoint) |
| 395 |
if err != nil { |
| 396 |
return nil, err |
| 397 |
} |
| 398 |
baseUrl.Path += fmt.Sprintf("/v1beta1/%v:annotate", req.GetName()) |
| 399 |
|
| 400 |
params := url.Values{} |
| 401 |
params.Add("$alt", "json;enum-encoding=int") |
| 402 |
|
| 403 |
baseUrl.RawQuery = params.Encode() |
| 404 |
|
| 405 |
// Build HTTP headers from client and context metadata. |
| 406 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| 407 |
|
| 408 |
hds = append(c.xGoogHeaders, hds...) |
| 409 |
hds = append(hds, "Content-Type", "application/json") |
| 410 |
headers := gax.BuildHeaders(ctx, hds...) |
| 411 |
opts = append((*c.CallOptions).AnnotateAssessment[0:len((*c.CallOptions).AnnotateAssessment):len((*c.CallOptions).AnnotateAssessment)], opts...) |
| 412 |
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| 413 |
resp := &recaptchaenterprisepb.AnnotateAssessmentResponse{} |
| 414 |
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 415 |
if settings.Path != "" { |
| 416 |
baseUrl.Path = settings.Path |
| 417 |
} |
| 418 |
httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) |
| 419 |
if err != nil { |
| 420 |
return err |
| 421 |
} |
| 422 |
httpReq = httpReq.WithContext(ctx) |
| 423 |
httpReq.Header = headers |
| 424 |
|
| 425 |
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "AnnotateAssessment") |
| 426 |
if err != nil { |
| 427 |
return err |
| 428 |
} |
| 429 |
|
| 430 |
if err := unm.Unmarshal(buf, resp); err != nil { |
| 431 |
return err |
| 432 |
} |
| 433 |
|
| 434 |
return nil |
| 435 |
}, opts...) |
| 436 |
if e != nil { |
| 437 |
return nil, e |
| 438 |
} |
| 439 |
return resp, nil |
| 440 |
} |