| 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/iterator" |
| 33 |
"google.golang.org/api/option" |
| 34 |
"google.golang.org/api/option/internaloption" |
| 35 |
gtransport "google.golang.org/api/transport/grpc" |
| 36 |
httptransport "google.golang.org/api/transport/http" |
| 37 |
"google.golang.org/grpc" |
| 38 |
"google.golang.org/grpc/codes" |
| 39 |
"google.golang.org/protobuf/encoding/protojson" |
| 40 |
"google.golang.org/protobuf/proto" |
| 41 |
) |
| 42 |
|
| 43 |
var newCompanyClientHook clientHook |
| 44 |
|
| 45 |
// CompanyCallOptions contains the retry settings for each method of CompanyClient. |
| 46 |
type CompanyCallOptions struct { |
| 47 |
CreateCompany []gax.CallOption |
| 48 |
GetCompany []gax.CallOption |
| 49 |
UpdateCompany []gax.CallOption |
| 50 |
DeleteCompany []gax.CallOption |
| 51 |
ListCompanies []gax.CallOption |
| 52 |
GetOperation []gax.CallOption |
| 53 |
} |
| 54 |
|
| 55 |
func defaultCompanyGRPCClientOptions() []option.ClientOption { |
| 56 |
return []option.ClientOption{ |
| 57 |
internaloption.WithDefaultEndpoint("jobs.googleapis.com:443"), |
| 58 |
internaloption.WithDefaultEndpointTemplate("jobs.UNIVERSE_DOMAIN:443"), |
| 59 |
internaloption.WithDefaultMTLSEndpoint("jobs.mtls.googleapis.com:443"), |
| 60 |
internaloption.WithDefaultUniverseDomain("googleapis.com"), |
| 61 |
internaloption.WithDefaultAudience("https://jobs.googleapis.com/"), |
| 62 |
internaloption.WithDefaultScopes(DefaultAuthScopes()...), |
| 63 |
internaloption.EnableJwtWithScope(), |
| 64 |
internaloption.EnableNewAuthLibrary(), |
| 65 |
option.WithGRPCDialOption(grpc.WithDefaultCallOptions( |
| 66 |
grpc.MaxCallRecvMsgSize(math.MaxInt32))), |
| 67 |
} |
| 68 |
} |
| 69 |
|
| 70 |
func defaultCompanyCallOptions() *CompanyCallOptions { |
| 71 |
return &CompanyCallOptions{ |
| 72 |
CreateCompany: []gax.CallOption{ |
| 73 |
gax.WithTimeout(30000 * time.Millisecond), |
| 74 |
}, |
| 75 |
GetCompany: []gax.CallOption{ |
| 76 |
gax.WithTimeout(30000 * time.Millisecond), |
| 77 |
gax.WithRetry(func() gax.Retryer { |
| 78 |
return gax.OnCodes([]codes.Code{ |
| 79 |
codes.DeadlineExceeded, |
| 80 |
codes.Unavailable, |
| 81 |
}, gax.Backoff{ |
| 82 |
Initial: 100 * time.Millisecond, |
| 83 |
Max: 60000 * time.Millisecond, |
| 84 |
Multiplier: 1.30, |
| 85 |
}) |
| 86 |
}), |
| 87 |
}, |
| 88 |
UpdateCompany: []gax.CallOption{ |
| 89 |
gax.WithTimeout(30000 * time.Millisecond), |
| 90 |
}, |
| 91 |
DeleteCompany: []gax.CallOption{ |
| 92 |
gax.WithTimeout(30000 * time.Millisecond), |
| 93 |
gax.WithRetry(func() gax.Retryer { |
| 94 |
return gax.OnCodes([]codes.Code{ |
| 95 |
codes.DeadlineExceeded, |
| 96 |
codes.Unavailable, |
| 97 |
}, gax.Backoff{ |
| 98 |
Initial: 100 * time.Millisecond, |
| 99 |
Max: 60000 * time.Millisecond, |
| 100 |
Multiplier: 1.30, |
| 101 |
}) |
| 102 |
}), |
| 103 |
}, |
| 104 |
ListCompanies: []gax.CallOption{ |
| 105 |
gax.WithTimeout(30000 * time.Millisecond), |
| 106 |
gax.WithRetry(func() gax.Retryer { |
| 107 |
return gax.OnCodes([]codes.Code{ |
| 108 |
codes.DeadlineExceeded, |
| 109 |
codes.Unavailable, |
| 110 |
}, gax.Backoff{ |
| 111 |
Initial: 100 * time.Millisecond, |
| 112 |
Max: 60000 * time.Millisecond, |
| 113 |
Multiplier: 1.30, |
| 114 |
}) |
| 115 |
}), |
| 116 |
}, |
| 117 |
GetOperation: []gax.CallOption{}, |
| 118 |
} |
| 119 |
} |
| 120 |
|
| 121 |
func defaultCompanyRESTCallOptions() *CompanyCallOptions { |
| 122 |
return &CompanyCallOptions{ |
| 123 |
CreateCompany: []gax.CallOption{ |
| 124 |
gax.WithTimeout(30000 * time.Millisecond), |
| 125 |
}, |
| 126 |
GetCompany: []gax.CallOption{ |
| 127 |
gax.WithTimeout(30000 * time.Millisecond), |
| 128 |
gax.WithRetry(func() gax.Retryer { |
| 129 |
return gax.OnHTTPCodes(gax.Backoff{ |
| 130 |
Initial: 100 * time.Millisecond, |
| 131 |
Max: 60000 * time.Millisecond, |
| 132 |
Multiplier: 1.30, |
| 133 |
}, |
| 134 |
http.StatusGatewayTimeout, |
| 135 |
http.StatusServiceUnavailable) |
| 136 |
}), |
| 137 |
}, |
| 138 |
UpdateCompany: []gax.CallOption{ |
| 139 |
gax.WithTimeout(30000 * time.Millisecond), |
| 140 |
}, |
| 141 |
DeleteCompany: []gax.CallOption{ |
| 142 |
gax.WithTimeout(30000 * time.Millisecond), |
| 143 |
gax.WithRetry(func() gax.Retryer { |
| 144 |
return gax.OnHTTPCodes(gax.Backoff{ |
| 145 |
Initial: 100 * time.Millisecond, |
| 146 |
Max: 60000 * time.Millisecond, |
| 147 |
Multiplier: 1.30, |
| 148 |
}, |
| 149 |
http.StatusGatewayTimeout, |
| 150 |
http.StatusServiceUnavailable) |
| 151 |
}), |
| 152 |
}, |
| 153 |
ListCompanies: []gax.CallOption{ |
| 154 |
gax.WithTimeout(30000 * time.Millisecond), |
| 155 |
gax.WithRetry(func() gax.Retryer { |
| 156 |
return gax.OnHTTPCodes(gax.Backoff{ |
| 157 |
Initial: 100 * time.Millisecond, |
| 158 |
Max: 60000 * time.Millisecond, |
| 159 |
Multiplier: 1.30, |
| 160 |
}, |
| 161 |
http.StatusGatewayTimeout, |
| 162 |
http.StatusServiceUnavailable) |
| 163 |
}), |
| 164 |
}, |
| 165 |
GetOperation: []gax.CallOption{}, |
| 166 |
} |
| 167 |
} |
| 168 |
|
| 169 |
// internalCompanyClient is an interface that defines the methods available from Cloud Talent Solution API. |
| 170 |
type internalCompanyClient interface { |
| 171 |
Close() error |
| 172 |
setGoogleClientInfo(...string) |
| 173 |
Connection() *grpc.ClientConn |
| 174 |
CreateCompany(context.Context, *talentpb.CreateCompanyRequest, ...gax.CallOption) (*talentpb.Company, error) |
| 175 |
GetCompany(context.Context, *talentpb.GetCompanyRequest, ...gax.CallOption) (*talentpb.Company, error) |
| 176 |
UpdateCompany(context.Context, *talentpb.UpdateCompanyRequest, ...gax.CallOption) (*talentpb.Company, error) |
| 177 |
DeleteCompany(context.Context, *talentpb.DeleteCompanyRequest, ...gax.CallOption) error |
| 178 |
ListCompanies(context.Context, *talentpb.ListCompaniesRequest, ...gax.CallOption) *CompanyIterator |
| 179 |
GetOperation(context.Context, *longrunningpb.GetOperationRequest, ...gax.CallOption) (*longrunningpb.Operation, error) |
| 180 |
} |
| 181 |
|
| 182 |
// CompanyClient is a client for interacting with Cloud Talent Solution API. |
| 183 |
// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. |
| 184 |
// |
| 185 |
// A service that handles company management, including CRUD and enumeration. |
| 186 |
type CompanyClient struct { |
| 187 |
// The internal transport-dependent client. |
| 188 |
internalClient internalCompanyClient |
| 189 |
|
| 190 |
// The call options for this service. |
| 191 |
CallOptions *CompanyCallOptions |
| 192 |
} |
| 193 |
|
| 194 |
// Wrapper methods routed to the internal client. |
| 195 |
|
| 196 |
// Close closes the connection to the API service. The user should invoke this when |
| 197 |
// the client is no longer required. |
| 198 |
func (c *CompanyClient) Close() error { |
| 199 |
return c.internalClient.Close() |
| 200 |
} |
| 201 |
|
| 202 |
// setGoogleClientInfo sets the name and version of the application in |
| 203 |
// the `x-goog-api-client` header passed on each request. Intended for |
| 204 |
// use by Google-written clients. |
| 205 |
func (c *CompanyClient) setGoogleClientInfo(keyval ...string) { |
| 206 |
c.internalClient.setGoogleClientInfo(keyval...) |
| 207 |
} |
| 208 |
|
| 209 |
// Connection returns a connection to the API service. |
| 210 |
// |
| 211 |
// Deprecated: Connections are now pooled so this method does not always |
| 212 |
// return the same resource. |
| 213 |
func (c *CompanyClient) Connection() *grpc.ClientConn { |
| 214 |
return c.internalClient.Connection() |
| 215 |
} |
| 216 |
|
| 217 |
// CreateCompany creates a new company entity. |
| 218 |
func (c *CompanyClient) CreateCompany(ctx context.Context, req *talentpb.CreateCompanyRequest, opts ...gax.CallOption) (*talentpb.Company, error) { |
| 219 |
return c.internalClient.CreateCompany(ctx, req, opts...) |
| 220 |
} |
| 221 |
|
| 222 |
// GetCompany retrieves specified company. |
| 223 |
func (c *CompanyClient) GetCompany(ctx context.Context, req *talentpb.GetCompanyRequest, opts ...gax.CallOption) (*talentpb.Company, error) { |
| 224 |
return c.internalClient.GetCompany(ctx, req, opts...) |
| 225 |
} |
| 226 |
|
| 227 |
// UpdateCompany updates specified company. |
| 228 |
func (c *CompanyClient) UpdateCompany(ctx context.Context, req *talentpb.UpdateCompanyRequest, opts ...gax.CallOption) (*talentpb.Company, error) { |
| 229 |
return c.internalClient.UpdateCompany(ctx, req, opts...) |
| 230 |
} |
| 231 |
|
| 232 |
// DeleteCompany deletes specified company. |
| 233 |
// Prerequisite: The company has no jobs associated with it. |
| 234 |
func (c *CompanyClient) DeleteCompany(ctx context.Context, req *talentpb.DeleteCompanyRequest, opts ...gax.CallOption) error { |
| 235 |
return c.internalClient.DeleteCompany(ctx, req, opts...) |
| 236 |
} |
| 237 |
|
| 238 |
// ListCompanies lists all companies associated with the project. |
| 239 |
func (c *CompanyClient) ListCompanies(ctx context.Context, req *talentpb.ListCompaniesRequest, opts ...gax.CallOption) *CompanyIterator { |
| 240 |
return c.internalClient.ListCompanies(ctx, req, opts...) |
| 241 |
} |
| 242 |
|
| 243 |
// GetOperation is a utility method from google.longrunning.Operations. |
| 244 |
func (c *CompanyClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) { |
| 245 |
return c.internalClient.GetOperation(ctx, req, opts...) |
| 246 |
} |
| 247 |
|
| 248 |
// companyGRPCClient is a client for interacting with Cloud Talent Solution API over gRPC transport. |
| 249 |
// |
| 250 |
// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. |
| 251 |
type companyGRPCClient struct { |
| 252 |
// Connection pool of gRPC connections to the service. |
| 253 |
connPool gtransport.ConnPool |
| 254 |
|
| 255 |
// Points back to the CallOptions field of the containing CompanyClient |
| 256 |
CallOptions **CompanyCallOptions |
| 257 |
|
| 258 |
// The gRPC API client. |
| 259 |
companyClient talentpb.CompanyServiceClient |
| 260 |
|
| 261 |
operationsClient longrunningpb.OperationsClient |
| 262 |
|
| 263 |
// The x-goog-* metadata to be sent with each request. |
| 264 |
xGoogHeaders []string |
| 265 |
|
| 266 |
logger *slog.Logger |
| 267 |
} |
| 268 |
|
| 269 |
// NewCompanyClient creates a new company service client based on gRPC. |
| 270 |
// The returned client must be Closed when it is done being used to clean up its underlying connections. |
| 271 |
// |
| 272 |
// A service that handles company management, including CRUD and enumeration. |
| 273 |
func NewCompanyClient(ctx context.Context, opts ...option.ClientOption) (*CompanyClient, error) { |
| 274 |
clientOpts := defaultCompanyGRPCClientOptions() |
| 275 |
if newCompanyClientHook != nil { |
| 276 |
hookOpts, err := newCompanyClientHook(ctx, clientHookParams{}) |
| 277 |
if err != nil { |
| 278 |
return nil, err |
| 279 |
} |
| 280 |
clientOpts = append(clientOpts, hookOpts...) |
| 281 |
} |
| 282 |
|
| 283 |
connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...) |
| 284 |
if err != nil { |
| 285 |
return nil, err |
| 286 |
} |
| 287 |
client := CompanyClient{CallOptions: defaultCompanyCallOptions()} |
| 288 |
|
| 289 |
c := &companyGRPCClient{ |
| 290 |
connPool: connPool, |
| 291 |
companyClient: talentpb.NewCompanyServiceClient(connPool), |
| 292 |
CallOptions: &client.CallOptions, |
| 293 |
logger: internaloption.GetLogger(opts), |
| 294 |
operationsClient: longrunningpb.NewOperationsClient(connPool), |
| 295 |
} |
| 296 |
c.setGoogleClientInfo() |
| 297 |
|
| 298 |
client.internalClient = c |
| 299 |
|
| 300 |
return &client, nil |
| 301 |
} |
| 302 |
|
| 303 |
// Connection returns a connection to the API service. |
| 304 |
// |
| 305 |
// Deprecated: Connections are now pooled so this method does not always |
| 306 |
// return the same resource. |
| 307 |
func (c *companyGRPCClient) Connection() *grpc.ClientConn { |
| 308 |
return c.connPool.Conn() |
| 309 |
} |
| 310 |
|
| 311 |
// setGoogleClientInfo sets the name and version of the application in |
| 312 |
// the `x-goog-api-client` header passed on each request. Intended for |
| 313 |
// use by Google-written clients. |
| 314 |
func (c *companyGRPCClient) setGoogleClientInfo(keyval ...string) { |
| 315 |
kv := append([]string{"gl-go", gax.GoVersion}, keyval...) |
| 316 |
kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "grpc", grpc.Version, "pb", protoVersion) |
| 317 |
c.xGoogHeaders = []string{ |
| 318 |
"x-goog-api-client", gax.XGoogHeader(kv...), |
| 319 |
} |
| 320 |
} |
| 321 |
|
| 322 |
// Close closes the connection to the API service. The user should invoke this when |
| 323 |
// the client is no longer required. |
| 324 |
func (c *companyGRPCClient) Close() error { |
| 325 |
return c.connPool.Close() |
| 326 |
} |
| 327 |
|
| 328 |
// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. |
| 329 |
type companyRESTClient struct { |
| 330 |
// The http endpoint to connect to. |
| 331 |
endpoint string |
| 332 |
|
| 333 |
// The http client. |
| 334 |
httpClient *http.Client |
| 335 |
|
| 336 |
// The x-goog-* headers to be sent with each request. |
| 337 |
xGoogHeaders []string |
| 338 |
|
| 339 |
// Points back to the CallOptions field of the containing CompanyClient |
| 340 |
CallOptions **CompanyCallOptions |
| 341 |
|
| 342 |
logger *slog.Logger |
| 343 |
} |
| 344 |
|
| 345 |
// NewCompanyRESTClient creates a new company service rest client. |
| 346 |
// |
| 347 |
// A service that handles company management, including CRUD and enumeration. |
| 348 |
func NewCompanyRESTClient(ctx context.Context, opts ...option.ClientOption) (*CompanyClient, error) { |
| 349 |
clientOpts := append(defaultCompanyRESTClientOptions(), opts...) |
| 350 |
httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...) |
| 351 |
if err != nil { |
| 352 |
return nil, err |
| 353 |
} |
| 354 |
|
| 355 |
callOpts := defaultCompanyRESTCallOptions() |
| 356 |
c := &companyRESTClient{ |
| 357 |
endpoint: endpoint, |
| 358 |
httpClient: httpClient, |
| 359 |
CallOptions: &callOpts, |
| 360 |
logger: internaloption.GetLogger(opts), |
| 361 |
} |
| 362 |
c.setGoogleClientInfo() |
| 363 |
|
| 364 |
return &CompanyClient{internalClient: c, CallOptions: callOpts}, nil |
| 365 |
} |
| 366 |
|
| 367 |
func defaultCompanyRESTClientOptions() []option.ClientOption { |
| 368 |
return []option.ClientOption{ |
| 369 |
internaloption.WithDefaultEndpoint("https://jobs.googleapis.com"), |
| 370 |
internaloption.WithDefaultEndpointTemplate("https://jobs.UNIVERSE_DOMAIN"), |
| 371 |
internaloption.WithDefaultMTLSEndpoint("https://jobs.mtls.googleapis.com"), |
| 372 |
internaloption.WithDefaultUniverseDomain("googleapis.com"), |
| 373 |
internaloption.WithDefaultAudience("https://jobs.googleapis.com/"), |
| 374 |
internaloption.WithDefaultScopes(DefaultAuthScopes()...), |
| 375 |
internaloption.EnableNewAuthLibrary(), |
| 376 |
} |
| 377 |
} |
| 378 |
|
| 379 |
// setGoogleClientInfo sets the name and version of the application in |
| 380 |
// the `x-goog-api-client` header passed on each request. Intended for |
| 381 |
// use by Google-written clients. |
| 382 |
func (c *companyRESTClient) setGoogleClientInfo(keyval ...string) { |
| 383 |
kv := append([]string{"gl-go", gax.GoVersion}, keyval...) |
| 384 |
kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "rest", "UNKNOWN", "pb", protoVersion) |
| 385 |
c.xGoogHeaders = []string{ |
| 386 |
"x-goog-api-client", gax.XGoogHeader(kv...), |
| 387 |
} |
| 388 |
} |
| 389 |
|
| 390 |
// Close closes the connection to the API service. The user should invoke this when |
| 391 |
// the client is no longer required. |
| 392 |
func (c *companyRESTClient) Close() error { |
| 393 |
// Replace httpClient with nil to force cleanup. |
| 394 |
c.httpClient = nil |
| 395 |
return nil |
| 396 |
} |
| 397 |
|
| 398 |
// Connection returns a connection to the API service. |
| 399 |
// |
| 400 |
// Deprecated: This method always returns nil. |
| 401 |
func (c *companyRESTClient) Connection() *grpc.ClientConn { |
| 402 |
return nil |
| 403 |
} |
| 404 |
func (c *companyGRPCClient) CreateCompany(ctx context.Context, req *talentpb.CreateCompanyRequest, opts ...gax.CallOption) (*talentpb.Company, error) { |
| 405 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))} |
| 406 |
|
| 407 |
hds = append(c.xGoogHeaders, hds...) |
| 408 |
ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) |
| 409 |
opts = append((*c.CallOptions).CreateCompany[0:len((*c.CallOptions).CreateCompany):len((*c.CallOptions).CreateCompany)], opts...) |
| 410 |
var resp *talentpb.Company |
| 411 |
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 412 |
var err error |
| 413 |
resp, err = executeRPC(ctx, c.companyClient.CreateCompany, req, settings.GRPC, c.logger, "CreateCompany") |
| 414 |
return err |
| 415 |
}, opts...) |
| 416 |
if err != nil { |
| 417 |
return nil, err |
| 418 |
} |
| 419 |
return resp, nil |
| 420 |
} |
| 421 |
|
| 422 |
func (c *companyGRPCClient) GetCompany(ctx context.Context, req *talentpb.GetCompanyRequest, opts ...gax.CallOption) (*talentpb.Company, error) { |
| 423 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| 424 |
|
| 425 |
hds = append(c.xGoogHeaders, hds...) |
| 426 |
ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) |
| 427 |
opts = append((*c.CallOptions).GetCompany[0:len((*c.CallOptions).GetCompany):len((*c.CallOptions).GetCompany)], opts...) |
| 428 |
var resp *talentpb.Company |
| 429 |
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 430 |
var err error |
| 431 |
resp, err = executeRPC(ctx, c.companyClient.GetCompany, req, settings.GRPC, c.logger, "GetCompany") |
| 432 |
return err |
| 433 |
}, opts...) |
| 434 |
if err != nil { |
| 435 |
return nil, err |
| 436 |
} |
| 437 |
return resp, nil |
| 438 |
} |
| 439 |
|
| 440 |
func (c *companyGRPCClient) UpdateCompany(ctx context.Context, req *talentpb.UpdateCompanyRequest, opts ...gax.CallOption) (*talentpb.Company, error) { |
| 441 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "company.name", url.QueryEscape(req.GetCompany().GetName()))} |
| 442 |
|
| 443 |
hds = append(c.xGoogHeaders, hds...) |
| 444 |
ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) |
| 445 |
opts = append((*c.CallOptions).UpdateCompany[0:len((*c.CallOptions).UpdateCompany):len((*c.CallOptions).UpdateCompany)], opts...) |
| 446 |
var resp *talentpb.Company |
| 447 |
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 448 |
var err error |
| 449 |
resp, err = executeRPC(ctx, c.companyClient.UpdateCompany, req, settings.GRPC, c.logger, "UpdateCompany") |
| 450 |
return err |
| 451 |
}, opts...) |
| 452 |
if err != nil { |
| 453 |
return nil, err |
| 454 |
} |
| 455 |
return resp, nil |
| 456 |
} |
| 457 |
|
| 458 |
func (c *companyGRPCClient) DeleteCompany(ctx context.Context, req *talentpb.DeleteCompanyRequest, opts ...gax.CallOption) error { |
| 459 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| 460 |
|
| 461 |
hds = append(c.xGoogHeaders, hds...) |
| 462 |
ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) |
| 463 |
opts = append((*c.CallOptions).DeleteCompany[0:len((*c.CallOptions).DeleteCompany):len((*c.CallOptions).DeleteCompany)], opts...) |
| 464 |
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 465 |
var err error |
| 466 |
_, err = executeRPC(ctx, c.companyClient.DeleteCompany, req, settings.GRPC, c.logger, "DeleteCompany") |
| 467 |
return err |
| 468 |
}, opts...) |
| 469 |
return err |
| 470 |
} |
| 471 |
|
| 472 |
func (c *companyGRPCClient) ListCompanies(ctx context.Context, req *talentpb.ListCompaniesRequest, opts ...gax.CallOption) *CompanyIterator { |
| 473 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))} |
| 474 |
|
| 475 |
hds = append(c.xGoogHeaders, hds...) |
| 476 |
ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) |
| 477 |
opts = append((*c.CallOptions).ListCompanies[0:len((*c.CallOptions).ListCompanies):len((*c.CallOptions).ListCompanies)], opts...) |
| 478 |
it := &CompanyIterator{} |
| 479 |
req = proto.Clone(req).(*talentpb.ListCompaniesRequest) |
| 480 |
it.InternalFetch = func(pageSize int, pageToken string) ([]*talentpb.Company, string, error) { |
| 481 |
resp := &talentpb.ListCompaniesResponse{} |
| 482 |
if pageToken != "" { |
| 483 |
req.PageToken = pageToken |
| 484 |
} |
| 485 |
if pageSize > math.MaxInt32 { |
| 486 |
req.PageSize = math.MaxInt32 |
| 487 |
} else if pageSize != 0 { |
| 488 |
req.PageSize = int32(pageSize) |
| 489 |
} |
| 490 |
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 491 |
var err error |
| 492 |
resp, err = executeRPC(ctx, c.companyClient.ListCompanies, req, settings.GRPC, c.logger, "ListCompanies") |
| 493 |
return err |
| 494 |
}, opts...) |
| 495 |
if err != nil { |
| 496 |
return nil, "", err |
| 497 |
} |
| 498 |
|
| 499 |
it.Response = resp |
| 500 |
return resp.GetCompanies(), resp.GetNextPageToken(), nil |
| 501 |
} |
| 502 |
fetch := func(pageSize int, pageToken string) (string, error) { |
| 503 |
items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) |
| 504 |
if err != nil { |
| 505 |
return "", err |
| 506 |
} |
| 507 |
it.items = append(it.items, items...) |
| 508 |
return nextPageToken, nil |
| 509 |
} |
| 510 |
|
| 511 |
it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) |
| 512 |
it.pageInfo.MaxSize = int(req.GetPageSize()) |
| 513 |
it.pageInfo.Token = req.GetPageToken() |
| 514 |
|
| 515 |
return it |
| 516 |
} |
| 517 |
|
| 518 |
func (c *companyGRPCClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) { |
| 519 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| 520 |
|
| 521 |
hds = append(c.xGoogHeaders, hds...) |
| 522 |
ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) |
| 523 |
opts = append((*c.CallOptions).GetOperation[0:len((*c.CallOptions).GetOperation):len((*c.CallOptions).GetOperation)], opts...) |
| 524 |
var resp *longrunningpb.Operation |
| 525 |
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 526 |
var err error |
| 527 |
resp, err = executeRPC(ctx, c.operationsClient.GetOperation, req, settings.GRPC, c.logger, "GetOperation") |
| 528 |
return err |
| 529 |
}, opts...) |
| 530 |
if err != nil { |
| 531 |
return nil, err |
| 532 |
} |
| 533 |
return resp, nil |
| 534 |
} |
| 535 |
|
| 536 |
// CreateCompany creates a new company entity. |
| 537 |
func (c *companyRESTClient) CreateCompany(ctx context.Context, req *talentpb.CreateCompanyRequest, opts ...gax.CallOption) (*talentpb.Company, error) { |
| 538 |
m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true} |
| 539 |
jsonReq, err := m.Marshal(req) |
| 540 |
if err != nil { |
| 541 |
return nil, err |
| 542 |
} |
| 543 |
|
| 544 |
baseUrl, err := url.Parse(c.endpoint) |
| 545 |
if err != nil { |
| 546 |
return nil, err |
| 547 |
} |
| 548 |
baseUrl.Path += fmt.Sprintf("/v4beta1/%v/companies", req.GetParent()) |
| 549 |
|
| 550 |
params := url.Values{} |
| 551 |
params.Add("$alt", "json;enum-encoding=int") |
| 552 |
|
| 553 |
baseUrl.RawQuery = params.Encode() |
| 554 |
|
| 555 |
// Build HTTP headers from client and context metadata. |
| 556 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))} |
| 557 |
|
| 558 |
hds = append(c.xGoogHeaders, hds...) |
| 559 |
hds = append(hds, "Content-Type", "application/json") |
| 560 |
headers := gax.BuildHeaders(ctx, hds...) |
| 561 |
opts = append((*c.CallOptions).CreateCompany[0:len((*c.CallOptions).CreateCompany):len((*c.CallOptions).CreateCompany)], opts...) |
| 562 |
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| 563 |
resp := &talentpb.Company{} |
| 564 |
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 565 |
if settings.Path != "" { |
| 566 |
baseUrl.Path = settings.Path |
| 567 |
} |
| 568 |
httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) |
| 569 |
if err != nil { |
| 570 |
return err |
| 571 |
} |
| 572 |
httpReq = httpReq.WithContext(ctx) |
| 573 |
httpReq.Header = headers |
| 574 |
|
| 575 |
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "CreateCompany") |
| 576 |
if err != nil { |
| 577 |
return err |
| 578 |
} |
| 579 |
|
| 580 |
if err := unm.Unmarshal(buf, resp); err != nil { |
| 581 |
return err |
| 582 |
} |
| 583 |
|
| 584 |
return nil |
| 585 |
}, opts...) |
| 586 |
if e != nil { |
| 587 |
return nil, e |
| 588 |
} |
| 589 |
return resp, nil |
| 590 |
} |
| 591 |
|
| 592 |
// GetCompany retrieves specified company. |
| 593 |
func (c *companyRESTClient) GetCompany(ctx context.Context, req *talentpb.GetCompanyRequest, opts ...gax.CallOption) (*talentpb.Company, error) { |
| 594 |
baseUrl, err := url.Parse(c.endpoint) |
| 595 |
if err != nil { |
| 596 |
return nil, err |
| 597 |
} |
| 598 |
baseUrl.Path += fmt.Sprintf("/v4beta1/%v", req.GetName()) |
| 599 |
|
| 600 |
params := url.Values{} |
| 601 |
params.Add("$alt", "json;enum-encoding=int") |
| 602 |
|
| 603 |
baseUrl.RawQuery = params.Encode() |
| 604 |
|
| 605 |
// Build HTTP headers from client and context metadata. |
| 606 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| 607 |
|
| 608 |
hds = append(c.xGoogHeaders, hds...) |
| 609 |
hds = append(hds, "Content-Type", "application/json") |
| 610 |
headers := gax.BuildHeaders(ctx, hds...) |
| 611 |
opts = append((*c.CallOptions).GetCompany[0:len((*c.CallOptions).GetCompany):len((*c.CallOptions).GetCompany)], opts...) |
| 612 |
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| 613 |
resp := &talentpb.Company{} |
| 614 |
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 615 |
if settings.Path != "" { |
| 616 |
baseUrl.Path = settings.Path |
| 617 |
} |
| 618 |
httpReq, err := http.NewRequest("GET", baseUrl.String(), nil) |
| 619 |
if err != nil { |
| 620 |
return err |
| 621 |
} |
| 622 |
httpReq = httpReq.WithContext(ctx) |
| 623 |
httpReq.Header = headers |
| 624 |
|
| 625 |
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetCompany") |
| 626 |
if err != nil { |
| 627 |
return err |
| 628 |
} |
| 629 |
|
| 630 |
if err := unm.Unmarshal(buf, resp); err != nil { |
| 631 |
return err |
| 632 |
} |
| 633 |
|
| 634 |
return nil |
| 635 |
}, opts...) |
| 636 |
if e != nil { |
| 637 |
return nil, e |
| 638 |
} |
| 639 |
return resp, nil |
| 640 |
} |
| 641 |
|
| 642 |
// UpdateCompany updates specified company. |
| 643 |
func (c *companyRESTClient) UpdateCompany(ctx context.Context, req *talentpb.UpdateCompanyRequest, opts ...gax.CallOption) (*talentpb.Company, error) { |
| 644 |
m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true} |
| 645 |
jsonReq, err := m.Marshal(req) |
| 646 |
if err != nil { |
| 647 |
return nil, err |
| 648 |
} |
| 649 |
|
| 650 |
baseUrl, err := url.Parse(c.endpoint) |
| 651 |
if err != nil { |
| 652 |
return nil, err |
| 653 |
} |
| 654 |
baseUrl.Path += fmt.Sprintf("/v4beta1/%v", req.GetCompany().GetName()) |
| 655 |
|
| 656 |
params := url.Values{} |
| 657 |
params.Add("$alt", "json;enum-encoding=int") |
| 658 |
|
| 659 |
baseUrl.RawQuery = params.Encode() |
| 660 |
|
| 661 |
// Build HTTP headers from client and context metadata. |
| 662 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "company.name", url.QueryEscape(req.GetCompany().GetName()))} |
| 663 |
|
| 664 |
hds = append(c.xGoogHeaders, hds...) |
| 665 |
hds = append(hds, "Content-Type", "application/json") |
| 666 |
headers := gax.BuildHeaders(ctx, hds...) |
| 667 |
opts = append((*c.CallOptions).UpdateCompany[0:len((*c.CallOptions).UpdateCompany):len((*c.CallOptions).UpdateCompany)], opts...) |
| 668 |
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| 669 |
resp := &talentpb.Company{} |
| 670 |
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 671 |
if settings.Path != "" { |
| 672 |
baseUrl.Path = settings.Path |
| 673 |
} |
| 674 |
httpReq, err := http.NewRequest("PATCH", baseUrl.String(), bytes.NewReader(jsonReq)) |
| 675 |
if err != nil { |
| 676 |
return err |
| 677 |
} |
| 678 |
httpReq = httpReq.WithContext(ctx) |
| 679 |
httpReq.Header = headers |
| 680 |
|
| 681 |
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "UpdateCompany") |
| 682 |
if err != nil { |
| 683 |
return err |
| 684 |
} |
| 685 |
|
| 686 |
if err := unm.Unmarshal(buf, resp); err != nil { |
| 687 |
return err |
| 688 |
} |
| 689 |
|
| 690 |
return nil |
| 691 |
}, opts...) |
| 692 |
if e != nil { |
| 693 |
return nil, e |
| 694 |
} |
| 695 |
return resp, nil |
| 696 |
} |
| 697 |
|
| 698 |
// DeleteCompany deletes specified company. |
| 699 |
// Prerequisite: The company has no jobs associated with it. |
| 700 |
func (c *companyRESTClient) DeleteCompany(ctx context.Context, req *talentpb.DeleteCompanyRequest, opts ...gax.CallOption) error { |
| 701 |
baseUrl, err := url.Parse(c.endpoint) |
| 702 |
if err != nil { |
| 703 |
return err |
| 704 |
} |
| 705 |
baseUrl.Path += fmt.Sprintf("/v4beta1/%v", req.GetName()) |
| 706 |
|
| 707 |
params := url.Values{} |
| 708 |
params.Add("$alt", "json;enum-encoding=int") |
| 709 |
|
| 710 |
baseUrl.RawQuery = params.Encode() |
| 711 |
|
| 712 |
// Build HTTP headers from client and context metadata. |
| 713 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| 714 |
|
| 715 |
hds = append(c.xGoogHeaders, hds...) |
| 716 |
hds = append(hds, "Content-Type", "application/json") |
| 717 |
headers := gax.BuildHeaders(ctx, hds...) |
| 718 |
return gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 719 |
if settings.Path != "" { |
| 720 |
baseUrl.Path = settings.Path |
| 721 |
} |
| 722 |
httpReq, err := http.NewRequest("DELETE", baseUrl.String(), nil) |
| 723 |
if err != nil { |
| 724 |
return err |
| 725 |
} |
| 726 |
httpReq = httpReq.WithContext(ctx) |
| 727 |
httpReq.Header = headers |
| 728 |
|
| 729 |
_, err = executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "DeleteCompany") |
| 730 |
return err |
| 731 |
}, opts...) |
| 732 |
} |
| 733 |
|
| 734 |
// ListCompanies lists all companies associated with the project. |
| 735 |
func (c *companyRESTClient) ListCompanies(ctx context.Context, req *talentpb.ListCompaniesRequest, opts ...gax.CallOption) *CompanyIterator { |
| 736 |
it := &CompanyIterator{} |
| 737 |
req = proto.Clone(req).(*talentpb.ListCompaniesRequest) |
| 738 |
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| 739 |
it.InternalFetch = func(pageSize int, pageToken string) ([]*talentpb.Company, string, error) { |
| 740 |
resp := &talentpb.ListCompaniesResponse{} |
| 741 |
if pageToken != "" { |
| 742 |
req.PageToken = pageToken |
| 743 |
} |
| 744 |
if pageSize > math.MaxInt32 { |
| 745 |
req.PageSize = math.MaxInt32 |
| 746 |
} else if pageSize != 0 { |
| 747 |
req.PageSize = int32(pageSize) |
| 748 |
} |
| 749 |
baseUrl, err := url.Parse(c.endpoint) |
| 750 |
if err != nil { |
| 751 |
return nil, "", err |
| 752 |
} |
| 753 |
baseUrl.Path += fmt.Sprintf("/v4beta1/%v/companies", req.GetParent()) |
| 754 |
|
| 755 |
params := url.Values{} |
| 756 |
params.Add("$alt", "json;enum-encoding=int") |
| 757 |
if req.GetPageSize() != 0 { |
| 758 |
params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize())) |
| 759 |
} |
| 760 |
if req.GetPageToken() != "" { |
| 761 |
params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) |
| 762 |
} |
| 763 |
if req.GetRequireOpenJobs() { |
| 764 |
params.Add("requireOpenJobs", fmt.Sprintf("%v", req.GetRequireOpenJobs())) |
| 765 |
} |
| 766 |
|
| 767 |
baseUrl.RawQuery = params.Encode() |
| 768 |
|
| 769 |
// Build HTTP headers from client and context metadata. |
| 770 |
hds := append(c.xGoogHeaders, "Content-Type", "application/json") |
| 771 |
headers := gax.BuildHeaders(ctx, hds...) |
| 772 |
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 773 |
if settings.Path != "" { |
| 774 |
baseUrl.Path = settings.Path |
| 775 |
} |
| 776 |
httpReq, err := http.NewRequest("GET", baseUrl.String(), nil) |
| 777 |
if err != nil { |
| 778 |
return err |
| 779 |
} |
| 780 |
httpReq.Header = headers |
| 781 |
|
| 782 |
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "ListCompanies") |
| 783 |
if err != nil { |
| 784 |
return err |
| 785 |
} |
| 786 |
if err := unm.Unmarshal(buf, resp); err != nil { |
| 787 |
return err |
| 788 |
} |
| 789 |
|
| 790 |
return nil |
| 791 |
}, opts...) |
| 792 |
if e != nil { |
| 793 |
return nil, "", e |
| 794 |
} |
| 795 |
it.Response = resp |
| 796 |
return resp.GetCompanies(), resp.GetNextPageToken(), nil |
| 797 |
} |
| 798 |
|
| 799 |
fetch := func(pageSize int, pageToken string) (string, error) { |
| 800 |
items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) |
| 801 |
if err != nil { |
| 802 |
return "", err |
| 803 |
} |
| 804 |
it.items = append(it.items, items...) |
| 805 |
return nextPageToken, nil |
| 806 |
} |
| 807 |
|
| 808 |
it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) |
| 809 |
it.pageInfo.MaxSize = int(req.GetPageSize()) |
| 810 |
it.pageInfo.Token = req.GetPageToken() |
| 811 |
|
| 812 |
return it |
| 813 |
} |
| 814 |
|
| 815 |
// GetOperation is a utility method from google.longrunning.Operations. |
| 816 |
func (c *companyRESTClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) { |
| 817 |
baseUrl, err := url.Parse(c.endpoint) |
| 818 |
if err != nil { |
| 819 |
return nil, err |
| 820 |
} |
| 821 |
baseUrl.Path += fmt.Sprintf("/v4beta1/%v", req.GetName()) |
| 822 |
|
| 823 |
params := url.Values{} |
| 824 |
params.Add("$alt", "json;enum-encoding=int") |
| 825 |
|
| 826 |
baseUrl.RawQuery = params.Encode() |
| 827 |
|
| 828 |
// Build HTTP headers from client and context metadata. |
| 829 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| 830 |
|
| 831 |
hds = append(c.xGoogHeaders, hds...) |
| 832 |
hds = append(hds, "Content-Type", "application/json") |
| 833 |
headers := gax.BuildHeaders(ctx, hds...) |
| 834 |
opts = append((*c.CallOptions).GetOperation[0:len((*c.CallOptions).GetOperation):len((*c.CallOptions).GetOperation)], opts...) |
| 835 |
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| 836 |
resp := &longrunningpb.Operation{} |
| 837 |
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 838 |
if settings.Path != "" { |
| 839 |
baseUrl.Path = settings.Path |
| 840 |
} |
| 841 |
httpReq, err := http.NewRequest("GET", baseUrl.String(), nil) |
| 842 |
if err != nil { |
| 843 |
return err |
| 844 |
} |
| 845 |
httpReq = httpReq.WithContext(ctx) |
| 846 |
httpReq.Header = headers |
| 847 |
|
| 848 |
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetOperation") |
| 849 |
if err != nil { |
| 850 |
return err |
| 851 |
} |
| 852 |
|
| 853 |
if err := unm.Unmarshal(buf, resp); err != nil { |
| 854 |
return err |
| 855 |
} |
| 856 |
|
| 857 |
return nil |
| 858 |
}, opts...) |
| 859 |
if e != nil { |
| 860 |
return nil, e |
| 861 |
} |
| 862 |
return resp, nil |
| 863 |
} |