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