diff --git a/internal/.repo-metadata-full.json b/internal/.repo-metadata-full.json index a539369885e..f5f7b66eeac 100644 --- a/internal/.repo-metadata-full.json +++ b/internal/.repo-metadata-full.json @@ -767,6 +767,14 @@ "docs_url": "https://pkg.go.dev/cloud.google.com/go/storage", "release_level": "ga" }, + "cloud.google.com/go/talent/apiv4": { + "distribution_name": "cloud.google.com/go/talent/apiv4", + "description": "", + "language": "Go", + "client_library_type": "generated", + "docs_url": "https://pkg.go.dev/cloud.google.com/go/talent/apiv4", + "release_level": "beta" + }, "cloud.google.com/go/talent/apiv4beta1": { "distribution_name": "cloud.google.com/go/talent/apiv4beta1", "description": "Cloud Talent Solution API", diff --git a/internal/gapicgen/generator/config.go b/internal/gapicgen/generator/config.go index 6e210608b21..aa2234ad8f1 100644 --- a/internal/gapicgen/generator/config.go +++ b/internal/gapicgen/generator/config.go @@ -664,6 +664,14 @@ var microgenGapicConfigs = []*microgenConfig{ apiServiceConfigPath: "google/logging/v2/logging.yaml", releaseLevel: "ga", }, + { + inputDirectoryPath: "google/cloud/talent/v4", + pkg: "talent", + importPath: "cloud.google.com/go/talent/apiv4", + gRPCServiceConfigPath: "google/cloud/talent/v4/talent_grpc_service_config.json", + apiServiceConfigPath: "google/cloud/talent/v4/talent_gapic.yaml", + releaseLevel: "beta", + }, { inputDirectoryPath: "google/cloud/talent/v4beta1", pkg: "talent", diff --git a/talent/apiv4/company_client.go b/talent/apiv4/company_client.go new file mode 100644 index 00000000000..4d773cb89ad --- /dev/null +++ b/talent/apiv4/company_client.go @@ -0,0 +1,320 @@ +// Copyright 2020 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by protoc-gen-go_gapic. DO NOT EDIT. + +package talent + +import ( + "context" + "fmt" + "math" + "net/url" + "time" + + "github.com/golang/protobuf/proto" + gax "github.com/googleapis/gax-go/v2" + "google.golang.org/api/iterator" + "google.golang.org/api/option" + gtransport "google.golang.org/api/transport/grpc" + talentpb "google.golang.org/genproto/googleapis/cloud/talent/v4" + "google.golang.org/grpc" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/metadata" +) + +var newCompanyClientHook clientHook + +// CompanyCallOptions contains the retry settings for each method of CompanyClient. +type CompanyCallOptions struct { + CreateCompany []gax.CallOption + GetCompany []gax.CallOption + UpdateCompany []gax.CallOption + DeleteCompany []gax.CallOption + ListCompanies []gax.CallOption +} + +func defaultCompanyClientOptions() []option.ClientOption { + return []option.ClientOption{ + option.WithEndpoint("jobs.googleapis.com:443"), + option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), + option.WithScopes(DefaultAuthScopes()...), + option.WithGRPCDialOption(grpc.WithDefaultCallOptions( + grpc.MaxCallRecvMsgSize(math.MaxInt32))), + } +} + +func defaultCompanyCallOptions() *CompanyCallOptions { + return &CompanyCallOptions{ + CreateCompany: []gax.CallOption{}, + GetCompany: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.DeadlineExceeded, + codes.Unavailable, + }, gax.Backoff{ + Initial: 100 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, + UpdateCompany: []gax.CallOption{}, + DeleteCompany: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.DeadlineExceeded, + codes.Unavailable, + }, gax.Backoff{ + Initial: 100 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, + ListCompanies: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.DeadlineExceeded, + codes.Unavailable, + }, gax.Backoff{ + Initial: 100 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, + } +} + +// CompanyClient is a client for interacting with . +// +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +type CompanyClient struct { + // Connection pool of gRPC connections to the service. + connPool gtransport.ConnPool + + // The gRPC API client. + companyClient talentpb.CompanyServiceClient + + // The call options for this service. + CallOptions *CompanyCallOptions + + // The x-goog-* metadata to be sent with each request. + xGoogMetadata metadata.MD +} + +// NewCompanyClient creates a new company service client. +// +// A service that handles company management, including CRUD and enumeration. +func NewCompanyClient(ctx context.Context, opts ...option.ClientOption) (*CompanyClient, error) { + clientOpts := defaultCompanyClientOptions() + + if newCompanyClientHook != nil { + hookOpts, err := newCompanyClientHook(ctx, clientHookParams{}) + if err != nil { + return nil, err + } + clientOpts = append(clientOpts, hookOpts...) + } + + connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...) + if err != nil { + return nil, err + } + c := &CompanyClient{ + connPool: connPool, + CallOptions: defaultCompanyCallOptions(), + + companyClient: talentpb.NewCompanyServiceClient(connPool), + } + c.setGoogleClientInfo() + + return c, nil +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *CompanyClient) Connection() *grpc.ClientConn { + return c.connPool.Conn() +} + +// Close closes the connection to the API service. The user should invoke this when +// the client is no longer required. +func (c *CompanyClient) Close() error { + return c.connPool.Close() +} + +// setGoogleClientInfo sets the name and version of the application in +// the `x-goog-api-client` header passed on each request. Intended for +// use by Google-written clients. +func (c *CompanyClient) setGoogleClientInfo(keyval ...string) { + kv := append([]string{"gl-go", versionGo()}, keyval...) + kv = append(kv, "gapic", versionClient, "gax", gax.Version, "grpc", grpc.Version) + c.xGoogMetadata = metadata.Pairs("x-goog-api-client", gax.XGoogHeader(kv...)) +} + +// CreateCompany creates a new company entity. +func (c *CompanyClient) CreateCompany(ctx context.Context, req *talentpb.CreateCompanyRequest, opts ...gax.CallOption) (*talentpb.Company, error) { + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append(c.CallOptions.CreateCompany[0:len(c.CallOptions.CreateCompany):len(c.CallOptions.CreateCompany)], opts...) + var resp *talentpb.Company + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.companyClient.CreateCompany(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +// GetCompany retrieves specified company. +func (c *CompanyClient) GetCompany(ctx context.Context, req *talentpb.GetCompanyRequest, opts ...gax.CallOption) (*talentpb.Company, error) { + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append(c.CallOptions.GetCompany[0:len(c.CallOptions.GetCompany):len(c.CallOptions.GetCompany)], opts...) + var resp *talentpb.Company + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.companyClient.GetCompany(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +// UpdateCompany updates specified company. +func (c *CompanyClient) UpdateCompany(ctx context.Context, req *talentpb.UpdateCompanyRequest, opts ...gax.CallOption) (*talentpb.Company, error) { + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "company.name", url.QueryEscape(req.GetCompany().GetName()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append(c.CallOptions.UpdateCompany[0:len(c.CallOptions.UpdateCompany):len(c.CallOptions.UpdateCompany)], opts...) + var resp *talentpb.Company + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.companyClient.UpdateCompany(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +// DeleteCompany deletes specified company. +// Prerequisite: The company has no jobs associated with it. +func (c *CompanyClient) DeleteCompany(ctx context.Context, req *talentpb.DeleteCompanyRequest, opts ...gax.CallOption) error { + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append(c.CallOptions.DeleteCompany[0:len(c.CallOptions.DeleteCompany):len(c.CallOptions.DeleteCompany)], opts...) + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + _, err = c.companyClient.DeleteCompany(ctx, req, settings.GRPC...) + return err + }, opts...) + return err +} + +// ListCompanies lists all companies associated with the project. +func (c *CompanyClient) ListCompanies(ctx context.Context, req *talentpb.ListCompaniesRequest, opts ...gax.CallOption) *CompanyIterator { + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append(c.CallOptions.ListCompanies[0:len(c.CallOptions.ListCompanies):len(c.CallOptions.ListCompanies)], opts...) + it := &CompanyIterator{} + req = proto.Clone(req).(*talentpb.ListCompaniesRequest) + it.InternalFetch = func(pageSize int, pageToken string) ([]*talentpb.Company, string, error) { + var resp *talentpb.ListCompaniesResponse + req.PageToken = pageToken + if pageSize > math.MaxInt32 { + req.PageSize = math.MaxInt32 + } else { + req.PageSize = int32(pageSize) + } + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.companyClient.ListCompanies(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, "", err + } + + it.Response = resp + return resp.Companies, resp.NextPageToken, nil + } + fetch := func(pageSize int, pageToken string) (string, error) { + items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) + if err != nil { + return "", err + } + it.items = append(it.items, items...) + return nextPageToken, nil + } + it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) + it.pageInfo.MaxSize = int(req.PageSize) + it.pageInfo.Token = req.PageToken + return it +} + +// CompanyIterator manages a stream of *talentpb.Company. +type CompanyIterator struct { + items []*talentpb.Company + pageInfo *iterator.PageInfo + nextFunc func() error + + // Response is the raw response for the current page. + // It must be cast to the RPC response type. + // Calling Next() or InternalFetch() updates this value. + Response interface{} + + // InternalFetch is for use by the Google Cloud Libraries only. + // It is not part of the stable interface of this package. + // + // InternalFetch returns results from a single call to the underlying RPC. + // The number of results is no greater than pageSize. + // If there are no more results, nextPageToken is empty and err is nil. + InternalFetch func(pageSize int, pageToken string) (results []*talentpb.Company, nextPageToken string, err error) +} + +// PageInfo supports pagination. See the google.golang.org/api/iterator package for details. +func (it *CompanyIterator) PageInfo() *iterator.PageInfo { + return it.pageInfo +} + +// Next returns the next result. Its second return value is iterator.Done if there are no more +// results. Once Next returns Done, all subsequent calls will return Done. +func (it *CompanyIterator) Next() (*talentpb.Company, error) { + var item *talentpb.Company + if err := it.nextFunc(); err != nil { + return item, err + } + item = it.items[0] + it.items = it.items[1:] + return item, nil +} + +func (it *CompanyIterator) bufLen() int { + return len(it.items) +} + +func (it *CompanyIterator) takeBuf() interface{} { + b := it.items + it.items = nil + return b +} diff --git a/talent/apiv4/company_client_example_test.go b/talent/apiv4/company_client_example_test.go new file mode 100644 index 00000000000..bff6008ff13 --- /dev/null +++ b/talent/apiv4/company_client_example_test.go @@ -0,0 +1,138 @@ +// Copyright 2020 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by protoc-gen-go_gapic. DO NOT EDIT. + +package talent_test + +import ( + "context" + + talent "cloud.google.com/go/talent/apiv4" + "google.golang.org/api/iterator" + talentpb "google.golang.org/genproto/googleapis/cloud/talent/v4" +) + +func ExampleNewCompanyClient() { + ctx := context.Background() + c, err := talent.NewCompanyClient(ctx) + if err != nil { + // TODO: Handle error. + } + // TODO: Use client. + _ = c +} + +func ExampleCompanyClient_CreateCompany() { + // import talentpb "google.golang.org/genproto/googleapis/cloud/talent/v4" + + ctx := context.Background() + c, err := talent.NewCompanyClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &talentpb.CreateCompanyRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.CreateCompany(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleCompanyClient_GetCompany() { + // import talentpb "google.golang.org/genproto/googleapis/cloud/talent/v4" + + ctx := context.Background() + c, err := talent.NewCompanyClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &talentpb.GetCompanyRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.GetCompany(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleCompanyClient_UpdateCompany() { + // import talentpb "google.golang.org/genproto/googleapis/cloud/talent/v4" + + ctx := context.Background() + c, err := talent.NewCompanyClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &talentpb.UpdateCompanyRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.UpdateCompany(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleCompanyClient_DeleteCompany() { + ctx := context.Background() + c, err := talent.NewCompanyClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &talentpb.DeleteCompanyRequest{ + // TODO: Fill request struct fields. + } + err = c.DeleteCompany(ctx, req) + if err != nil { + // TODO: Handle error. + } +} + +func ExampleCompanyClient_ListCompanies() { + // import talentpb "google.golang.org/genproto/googleapis/cloud/talent/v4" + // import "google.golang.org/api/iterator" + + ctx := context.Background() + c, err := talent.NewCompanyClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &talentpb.ListCompaniesRequest{ + // TODO: Fill request struct fields. + } + it := c.ListCompanies(ctx, req) + for { + resp, err := it.Next() + if err == iterator.Done { + break + } + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp + } +} diff --git a/talent/apiv4/completion_client.go b/talent/apiv4/completion_client.go new file mode 100644 index 00000000000..01f9f7e49e7 --- /dev/null +++ b/talent/apiv4/completion_client.go @@ -0,0 +1,153 @@ +// Copyright 2020 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by protoc-gen-go_gapic. DO NOT EDIT. + +package talent + +import ( + "context" + "fmt" + "math" + "net/url" + "time" + + gax "github.com/googleapis/gax-go/v2" + "google.golang.org/api/option" + gtransport "google.golang.org/api/transport/grpc" + talentpb "google.golang.org/genproto/googleapis/cloud/talent/v4" + "google.golang.org/grpc" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/metadata" +) + +var newCompletionClientHook clientHook + +// CompletionCallOptions contains the retry settings for each method of CompletionClient. +type CompletionCallOptions struct { + CompleteQuery []gax.CallOption +} + +func defaultCompletionClientOptions() []option.ClientOption { + return []option.ClientOption{ + option.WithEndpoint("jobs.googleapis.com:443"), + option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), + option.WithScopes(DefaultAuthScopes()...), + option.WithGRPCDialOption(grpc.WithDefaultCallOptions( + grpc.MaxCallRecvMsgSize(math.MaxInt32))), + } +} + +func defaultCompletionCallOptions() *CompletionCallOptions { + return &CompletionCallOptions{ + CompleteQuery: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.DeadlineExceeded, + codes.Unavailable, + }, gax.Backoff{ + Initial: 100 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, + } +} + +// CompletionClient is a client for interacting with . +// +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +type CompletionClient struct { + // Connection pool of gRPC connections to the service. + connPool gtransport.ConnPool + + // The gRPC API client. + completionClient talentpb.CompletionClient + + // The call options for this service. + CallOptions *CompletionCallOptions + + // The x-goog-* metadata to be sent with each request. + xGoogMetadata metadata.MD +} + +// NewCompletionClient creates a new completion client. +// +// A service handles auto completion. +func NewCompletionClient(ctx context.Context, opts ...option.ClientOption) (*CompletionClient, error) { + clientOpts := defaultCompletionClientOptions() + + if newCompletionClientHook != nil { + hookOpts, err := newCompletionClientHook(ctx, clientHookParams{}) + if err != nil { + return nil, err + } + clientOpts = append(clientOpts, hookOpts...) + } + + connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...) + if err != nil { + return nil, err + } + c := &CompletionClient{ + connPool: connPool, + CallOptions: defaultCompletionCallOptions(), + + completionClient: talentpb.NewCompletionClient(connPool), + } + c.setGoogleClientInfo() + + return c, nil +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *CompletionClient) Connection() *grpc.ClientConn { + return c.connPool.Conn() +} + +// Close closes the connection to the API service. The user should invoke this when +// the client is no longer required. +func (c *CompletionClient) Close() error { + return c.connPool.Close() +} + +// setGoogleClientInfo sets the name and version of the application in +// the `x-goog-api-client` header passed on each request. Intended for +// use by Google-written clients. +func (c *CompletionClient) setGoogleClientInfo(keyval ...string) { + kv := append([]string{"gl-go", versionGo()}, keyval...) + kv = append(kv, "gapic", versionClient, "gax", gax.Version, "grpc", grpc.Version) + c.xGoogMetadata = metadata.Pairs("x-goog-api-client", gax.XGoogHeader(kv...)) +} + +// CompleteQuery completes the specified prefix with keyword suggestions. +// Intended for use by a job search auto-complete search box. +func (c *CompletionClient) CompleteQuery(ctx context.Context, req *talentpb.CompleteQueryRequest, opts ...gax.CallOption) (*talentpb.CompleteQueryResponse, error) { + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "tenant", url.QueryEscape(req.GetTenant()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append(c.CallOptions.CompleteQuery[0:len(c.CallOptions.CompleteQuery):len(c.CallOptions.CompleteQuery)], opts...) + var resp *talentpb.CompleteQueryResponse + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.completionClient.CompleteQuery(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} diff --git a/talent/apiv4/completion_client_example_test.go b/talent/apiv4/completion_client_example_test.go new file mode 100644 index 00000000000..651b5985993 --- /dev/null +++ b/talent/apiv4/completion_client_example_test.go @@ -0,0 +1,54 @@ +// Copyright 2020 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by protoc-gen-go_gapic. DO NOT EDIT. + +package talent_test + +import ( + "context" + + talent "cloud.google.com/go/talent/apiv4" + talentpb "google.golang.org/genproto/googleapis/cloud/talent/v4" +) + +func ExampleNewCompletionClient() { + ctx := context.Background() + c, err := talent.NewCompletionClient(ctx) + if err != nil { + // TODO: Handle error. + } + // TODO: Use client. + _ = c +} + +func ExampleCompletionClient_CompleteQuery() { + // import talentpb "google.golang.org/genproto/googleapis/cloud/talent/v4" + + ctx := context.Background() + c, err := talent.NewCompletionClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &talentpb.CompleteQueryRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.CompleteQuery(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} diff --git a/talent/apiv4/doc.go b/talent/apiv4/doc.go new file mode 100644 index 00000000000..ef105428ac0 --- /dev/null +++ b/talent/apiv4/doc.go @@ -0,0 +1,103 @@ +// Copyright 2020 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by protoc-gen-go_gapic. DO NOT EDIT. + +// +// NOTE: This package is in beta. It is not stable, and may be subject to changes. +// +// Use of Context +// +// The ctx passed to NewClient is used for authentication requests and +// for creating the underlying connection, but is not used for subsequent calls. +// Individual methods on the client use the ctx given to them. +// +// To close the open connection, use the Close() method. +// +// For information about setting deadlines, reusing contexts, and more +// please visit godoc.org/cloud.google.com/go. +package talent // import "cloud.google.com/go/talent/apiv4" + +import ( + "context" + "runtime" + "strings" + "unicode" + + "google.golang.org/api/option" + "google.golang.org/grpc/metadata" +) + +// For more information on implementing a client constructor hook, see +// https://github.com/googleapis/google-cloud-go/wiki/Customizing-constructors. +type clientHookParams struct{} +type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) + +const versionClient = "20200916" + +func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { + out, _ := metadata.FromOutgoingContext(ctx) + out = out.Copy() + for _, md := range mds { + for k, v := range md { + out[k] = append(out[k], v...) + } + } + return metadata.NewOutgoingContext(ctx, out) +} + +// DefaultAuthScopes reports the default set of authentication scopes to use with this package. +func DefaultAuthScopes() []string { + return []string{ + "https://www.googleapis.com/auth/cloud-platform", + "https://www.googleapis.com/auth/jobs", + } +} + +// versionGo returns the Go runtime version. The returned string +// has no whitespace, suitable for reporting in header. +func versionGo() string { + const develPrefix = "devel +" + + s := runtime.Version() + if strings.HasPrefix(s, develPrefix) { + s = s[len(develPrefix):] + if p := strings.IndexFunc(s, unicode.IsSpace); p >= 0 { + s = s[:p] + } + return s + } + + notSemverRune := func(r rune) bool { + return !strings.ContainsRune("0123456789.", r) + } + + if strings.HasPrefix(s, "go1") { + s = s[2:] + var prerelease string + if p := strings.IndexFunc(s, notSemverRune); p >= 0 { + s, prerelease = s[:p], s[p:] + } + if strings.HasSuffix(s, ".") { + s += "0" + } else if strings.Count(s, ".") < 2 { + s += ".0" + } + if prerelease != "" { + s += "-" + prerelease + } + return s + } + return "UNKNOWN" +} diff --git a/talent/apiv4/event_client.go b/talent/apiv4/event_client.go new file mode 100644 index 00000000000..bb6438acd17 --- /dev/null +++ b/talent/apiv4/event_client.go @@ -0,0 +1,145 @@ +// Copyright 2020 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by protoc-gen-go_gapic. DO NOT EDIT. + +package talent + +import ( + "context" + "fmt" + "math" + "net/url" + + gax "github.com/googleapis/gax-go/v2" + "google.golang.org/api/option" + gtransport "google.golang.org/api/transport/grpc" + talentpb "google.golang.org/genproto/googleapis/cloud/talent/v4" + "google.golang.org/grpc" + "google.golang.org/grpc/metadata" +) + +var newEventClientHook clientHook + +// EventCallOptions contains the retry settings for each method of EventClient. +type EventCallOptions struct { + CreateClientEvent []gax.CallOption +} + +func defaultEventClientOptions() []option.ClientOption { + return []option.ClientOption{ + option.WithEndpoint("jobs.googleapis.com:443"), + option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), + option.WithScopes(DefaultAuthScopes()...), + option.WithGRPCDialOption(grpc.WithDefaultCallOptions( + grpc.MaxCallRecvMsgSize(math.MaxInt32))), + } +} + +func defaultEventCallOptions() *EventCallOptions { + return &EventCallOptions{ + CreateClientEvent: []gax.CallOption{}, + } +} + +// EventClient is a client for interacting with . +// +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +type EventClient struct { + // Connection pool of gRPC connections to the service. + connPool gtransport.ConnPool + + // The gRPC API client. + eventClient talentpb.EventServiceClient + + // The call options for this service. + CallOptions *EventCallOptions + + // The x-goog-* metadata to be sent with each request. + xGoogMetadata metadata.MD +} + +// NewEventClient creates a new event service client. +// +// A service handles client event report. +func NewEventClient(ctx context.Context, opts ...option.ClientOption) (*EventClient, error) { + clientOpts := defaultEventClientOptions() + + if newEventClientHook != nil { + hookOpts, err := newEventClientHook(ctx, clientHookParams{}) + if err != nil { + return nil, err + } + clientOpts = append(clientOpts, hookOpts...) + } + + connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...) + if err != nil { + return nil, err + } + c := &EventClient{ + connPool: connPool, + CallOptions: defaultEventCallOptions(), + + eventClient: talentpb.NewEventServiceClient(connPool), + } + c.setGoogleClientInfo() + + return c, nil +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *EventClient) Connection() *grpc.ClientConn { + return c.connPool.Conn() +} + +// Close closes the connection to the API service. The user should invoke this when +// the client is no longer required. +func (c *EventClient) Close() error { + return c.connPool.Close() +} + +// setGoogleClientInfo sets the name and version of the application in +// the `x-goog-api-client` header passed on each request. Intended for +// use by Google-written clients. +func (c *EventClient) setGoogleClientInfo(keyval ...string) { + kv := append([]string{"gl-go", versionGo()}, keyval...) + kv = append(kv, "gapic", versionClient, "gax", gax.Version, "grpc", grpc.Version) + c.xGoogMetadata = metadata.Pairs("x-goog-api-client", gax.XGoogHeader(kv...)) +} + +// CreateClientEvent report events issued when end user interacts with customer’s application +// that uses Cloud Talent Solution. You may inspect the created events in +// self service +// tools (at https://console.cloud.google.com/talent-solution/overview). +// Learn +// more (at https://cloud.google.com/talent-solution/docs/management-tools) +// about self service tools. +func (c *EventClient) CreateClientEvent(ctx context.Context, req *talentpb.CreateClientEventRequest, opts ...gax.CallOption) (*talentpb.ClientEvent, error) { + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append(c.CallOptions.CreateClientEvent[0:len(c.CallOptions.CreateClientEvent):len(c.CallOptions.CreateClientEvent)], opts...) + var resp *talentpb.ClientEvent + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.eventClient.CreateClientEvent(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} diff --git a/talent/apiv4/event_client_example_test.go b/talent/apiv4/event_client_example_test.go new file mode 100644 index 00000000000..9a5fe110d1e --- /dev/null +++ b/talent/apiv4/event_client_example_test.go @@ -0,0 +1,54 @@ +// Copyright 2020 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by protoc-gen-go_gapic. DO NOT EDIT. + +package talent_test + +import ( + "context" + + talent "cloud.google.com/go/talent/apiv4" + talentpb "google.golang.org/genproto/googleapis/cloud/talent/v4" +) + +func ExampleNewEventClient() { + ctx := context.Background() + c, err := talent.NewEventClient(ctx) + if err != nil { + // TODO: Handle error. + } + // TODO: Use client. + _ = c +} + +func ExampleEventClient_CreateClientEvent() { + // import talentpb "google.golang.org/genproto/googleapis/cloud/talent/v4" + + ctx := context.Background() + c, err := talent.NewEventClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &talentpb.CreateClientEventRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.CreateClientEvent(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} diff --git a/talent/apiv4/job_client.go b/talent/apiv4/job_client.go new file mode 100644 index 00000000000..3fda817009d --- /dev/null +++ b/talent/apiv4/job_client.go @@ -0,0 +1,668 @@ +// Copyright 2020 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by protoc-gen-go_gapic. DO NOT EDIT. + +package talent + +import ( + "context" + "fmt" + "math" + "net/url" + "time" + + "cloud.google.com/go/longrunning" + lroauto "cloud.google.com/go/longrunning/autogen" + "github.com/golang/protobuf/proto" + gax "github.com/googleapis/gax-go/v2" + "google.golang.org/api/iterator" + "google.golang.org/api/option" + gtransport "google.golang.org/api/transport/grpc" + talentpb "google.golang.org/genproto/googleapis/cloud/talent/v4" + longrunningpb "google.golang.org/genproto/googleapis/longrunning" + "google.golang.org/grpc" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/metadata" +) + +var newJobClientHook clientHook + +// JobCallOptions contains the retry settings for each method of JobClient. +type JobCallOptions struct { + CreateJob []gax.CallOption + BatchCreateJobs []gax.CallOption + GetJob []gax.CallOption + UpdateJob []gax.CallOption + BatchUpdateJobs []gax.CallOption + DeleteJob []gax.CallOption + BatchDeleteJobs []gax.CallOption + ListJobs []gax.CallOption + SearchJobs []gax.CallOption + SearchJobsForAlert []gax.CallOption +} + +func defaultJobClientOptions() []option.ClientOption { + return []option.ClientOption{ + option.WithEndpoint("jobs.googleapis.com:443"), + option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), + option.WithScopes(DefaultAuthScopes()...), + option.WithGRPCDialOption(grpc.WithDefaultCallOptions( + grpc.MaxCallRecvMsgSize(math.MaxInt32))), + } +} + +func defaultJobCallOptions() *JobCallOptions { + return &JobCallOptions{ + CreateJob: []gax.CallOption{}, + BatchCreateJobs: []gax.CallOption{}, + GetJob: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.DeadlineExceeded, + codes.Unavailable, + }, gax.Backoff{ + Initial: 100 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, + UpdateJob: []gax.CallOption{}, + BatchUpdateJobs: []gax.CallOption{}, + DeleteJob: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.DeadlineExceeded, + codes.Unavailable, + }, gax.Backoff{ + Initial: 100 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, + BatchDeleteJobs: []gax.CallOption{}, + ListJobs: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.DeadlineExceeded, + codes.Unavailable, + }, gax.Backoff{ + Initial: 100 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, + SearchJobs: []gax.CallOption{}, + SearchJobsForAlert: []gax.CallOption{}, + } +} + +// JobClient is a client for interacting with . +// +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +type JobClient struct { + // Connection pool of gRPC connections to the service. + connPool gtransport.ConnPool + + // The gRPC API client. + jobClient talentpb.JobServiceClient + + // LROClient is used internally to handle longrunning operations. + // It is exposed so that its CallOptions can be modified if required. + // Users should not Close this client. + LROClient *lroauto.OperationsClient + + // The call options for this service. + CallOptions *JobCallOptions + + // The x-goog-* metadata to be sent with each request. + xGoogMetadata metadata.MD +} + +// NewJobClient creates a new job service client. +// +// A service handles job management, including job CRUD, enumeration and search. +func NewJobClient(ctx context.Context, opts ...option.ClientOption) (*JobClient, error) { + clientOpts := defaultJobClientOptions() + + if newJobClientHook != nil { + hookOpts, err := newJobClientHook(ctx, clientHookParams{}) + if err != nil { + return nil, err + } + clientOpts = append(clientOpts, hookOpts...) + } + + connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...) + if err != nil { + return nil, err + } + c := &JobClient{ + connPool: connPool, + CallOptions: defaultJobCallOptions(), + + jobClient: talentpb.NewJobServiceClient(connPool), + } + c.setGoogleClientInfo() + + c.LROClient, err = lroauto.NewOperationsClient(ctx, gtransport.WithConnPool(connPool)) + if err != nil { + // This error "should not happen", since we are just reusing old connection pool + // and never actually need to dial. + // If this does happen, we could leak connp. However, we cannot close conn: + // If the user invoked the constructor with option.WithGRPCConn, + // we would close a connection that's still in use. + // TODO: investigate error conditions. + return nil, err + } + return c, nil +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *JobClient) Connection() *grpc.ClientConn { + return c.connPool.Conn() +} + +// Close closes the connection to the API service. The user should invoke this when +// the client is no longer required. +func (c *JobClient) Close() error { + return c.connPool.Close() +} + +// setGoogleClientInfo sets the name and version of the application in +// the `x-goog-api-client` header passed on each request. Intended for +// use by Google-written clients. +func (c *JobClient) setGoogleClientInfo(keyval ...string) { + kv := append([]string{"gl-go", versionGo()}, keyval...) + kv = append(kv, "gapic", versionClient, "gax", gax.Version, "grpc", grpc.Version) + c.xGoogMetadata = metadata.Pairs("x-goog-api-client", gax.XGoogHeader(kv...)) +} + +// CreateJob creates a new job. +// +// Typically, the job becomes searchable within 10 seconds, but it may take +// up to 5 minutes. +func (c *JobClient) CreateJob(ctx context.Context, req *talentpb.CreateJobRequest, opts ...gax.CallOption) (*talentpb.Job, error) { + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append(c.CallOptions.CreateJob[0:len(c.CallOptions.CreateJob):len(c.CallOptions.CreateJob)], opts...) + var resp *talentpb.Job + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.jobClient.CreateJob(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +// BatchCreateJobs begins executing a batch create jobs operation. +func (c *JobClient) BatchCreateJobs(ctx context.Context, req *talentpb.BatchCreateJobsRequest, opts ...gax.CallOption) (*BatchCreateJobsOperation, error) { + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append(c.CallOptions.BatchCreateJobs[0:len(c.CallOptions.BatchCreateJobs):len(c.CallOptions.BatchCreateJobs)], opts...) + var resp *longrunningpb.Operation + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.jobClient.BatchCreateJobs(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return &BatchCreateJobsOperation{ + lro: longrunning.InternalNewOperation(c.LROClient, resp), + }, nil +} + +// GetJob retrieves the specified job, whose status is OPEN or recently EXPIRED +// within the last 90 days. +func (c *JobClient) GetJob(ctx context.Context, req *talentpb.GetJobRequest, opts ...gax.CallOption) (*talentpb.Job, error) { + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append(c.CallOptions.GetJob[0:len(c.CallOptions.GetJob):len(c.CallOptions.GetJob)], opts...) + var resp *talentpb.Job + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.jobClient.GetJob(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +// UpdateJob updates specified job. +// +// Typically, updated contents become visible in search results within 10 +// seconds, but it may take up to 5 minutes. +func (c *JobClient) UpdateJob(ctx context.Context, req *talentpb.UpdateJobRequest, opts ...gax.CallOption) (*talentpb.Job, error) { + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "job.name", url.QueryEscape(req.GetJob().GetName()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append(c.CallOptions.UpdateJob[0:len(c.CallOptions.UpdateJob):len(c.CallOptions.UpdateJob)], opts...) + var resp *talentpb.Job + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.jobClient.UpdateJob(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +// BatchUpdateJobs begins executing a batch update jobs operation. +func (c *JobClient) BatchUpdateJobs(ctx context.Context, req *talentpb.BatchUpdateJobsRequest, opts ...gax.CallOption) (*BatchUpdateJobsOperation, error) { + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append(c.CallOptions.BatchUpdateJobs[0:len(c.CallOptions.BatchUpdateJobs):len(c.CallOptions.BatchUpdateJobs)], opts...) + var resp *longrunningpb.Operation + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.jobClient.BatchUpdateJobs(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return &BatchUpdateJobsOperation{ + lro: longrunning.InternalNewOperation(c.LROClient, resp), + }, nil +} + +// DeleteJob deletes the specified job. +// +// Typically, the job becomes unsearchable within 10 seconds, but it may take +// up to 5 minutes. +func (c *JobClient) DeleteJob(ctx context.Context, req *talentpb.DeleteJobRequest, opts ...gax.CallOption) error { + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append(c.CallOptions.DeleteJob[0:len(c.CallOptions.DeleteJob):len(c.CallOptions.DeleteJob)], opts...) + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + _, err = c.jobClient.DeleteJob(ctx, req, settings.GRPC...) + return err + }, opts...) + return err +} + +// BatchDeleteJobs begins executing a batch delete jobs operation. +func (c *JobClient) BatchDeleteJobs(ctx context.Context, req *talentpb.BatchDeleteJobsRequest, opts ...gax.CallOption) (*BatchDeleteJobsOperation, error) { + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append(c.CallOptions.BatchDeleteJobs[0:len(c.CallOptions.BatchDeleteJobs):len(c.CallOptions.BatchDeleteJobs)], opts...) + var resp *longrunningpb.Operation + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.jobClient.BatchDeleteJobs(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return &BatchDeleteJobsOperation{ + lro: longrunning.InternalNewOperation(c.LROClient, resp), + }, nil +} + +// ListJobs lists jobs by filter. +func (c *JobClient) ListJobs(ctx context.Context, req *talentpb.ListJobsRequest, opts ...gax.CallOption) *JobIterator { + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append(c.CallOptions.ListJobs[0:len(c.CallOptions.ListJobs):len(c.CallOptions.ListJobs)], opts...) + it := &JobIterator{} + req = proto.Clone(req).(*talentpb.ListJobsRequest) + it.InternalFetch = func(pageSize int, pageToken string) ([]*talentpb.Job, string, error) { + var resp *talentpb.ListJobsResponse + req.PageToken = pageToken + if pageSize > math.MaxInt32 { + req.PageSize = math.MaxInt32 + } else { + req.PageSize = int32(pageSize) + } + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.jobClient.ListJobs(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, "", err + } + + it.Response = resp + return resp.Jobs, resp.NextPageToken, nil + } + fetch := func(pageSize int, pageToken string) (string, error) { + items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) + if err != nil { + return "", err + } + it.items = append(it.items, items...) + return nextPageToken, nil + } + it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) + it.pageInfo.MaxSize = int(req.PageSize) + it.pageInfo.Token = req.PageToken + return it +} + +// SearchJobs searches for jobs using the provided SearchJobsRequest. +// +// This call constrains the visibility of jobs +// present in the database, and only returns jobs that the caller has +// permission to search against. +func (c *JobClient) SearchJobs(ctx context.Context, req *talentpb.SearchJobsRequest, opts ...gax.CallOption) (*talentpb.SearchJobsResponse, error) { + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append(c.CallOptions.SearchJobs[0:len(c.CallOptions.SearchJobs):len(c.CallOptions.SearchJobs)], opts...) + var resp *talentpb.SearchJobsResponse + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.jobClient.SearchJobs(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +// SearchJobsForAlert searches for jobs using the provided SearchJobsRequest. +// +// This API call is intended for the use case of targeting passive job +// seekers (for example, job seekers who have signed up to receive email +// alerts about potential job opportunities), it has different algorithmic +// adjustments that are designed to specifically target passive job seekers. +// +// This call constrains the visibility of jobs +// present in the database, and only returns jobs the caller has +// permission to search against. +func (c *JobClient) SearchJobsForAlert(ctx context.Context, req *talentpb.SearchJobsRequest, opts ...gax.CallOption) (*talentpb.SearchJobsResponse, error) { + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append(c.CallOptions.SearchJobsForAlert[0:len(c.CallOptions.SearchJobsForAlert):len(c.CallOptions.SearchJobsForAlert)], opts...) + var resp *talentpb.SearchJobsResponse + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.jobClient.SearchJobsForAlert(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +// BatchCreateJobsOperation manages a long-running operation from BatchCreateJobs. +type BatchCreateJobsOperation struct { + lro *longrunning.Operation +} + +// BatchCreateJobsOperation returns a new BatchCreateJobsOperation from a given name. +// The name must be that of a previously created BatchCreateJobsOperation, possibly from a different process. +func (c *JobClient) BatchCreateJobsOperation(name string) *BatchCreateJobsOperation { + return &BatchCreateJobsOperation{ + lro: longrunning.InternalNewOperation(c.LROClient, &longrunningpb.Operation{Name: name}), + } +} + +// Wait blocks until the long-running operation is completed, returning the response and any errors encountered. +// +// See documentation of Poll for error-handling information. +func (op *BatchCreateJobsOperation) Wait(ctx context.Context, opts ...gax.CallOption) (*talentpb.BatchCreateJobsResponse, error) { + var resp talentpb.BatchCreateJobsResponse + if err := op.lro.WaitWithInterval(ctx, &resp, time.Minute, opts...); err != nil { + return nil, err + } + return &resp, nil +} + +// Poll fetches the latest state of the long-running operation. +// +// Poll also fetches the latest metadata, which can be retrieved by Metadata. +// +// If Poll fails, the error is returned and op is unmodified. If Poll succeeds and +// the operation has completed with failure, the error is returned and op.Done will return true. +// If Poll succeeds and the operation has completed successfully, +// op.Done will return true, and the response of the operation is returned. +// If Poll succeeds and the operation has not completed, the returned response and error are both nil. +func (op *BatchCreateJobsOperation) Poll(ctx context.Context, opts ...gax.CallOption) (*talentpb.BatchCreateJobsResponse, error) { + var resp talentpb.BatchCreateJobsResponse + if err := op.lro.Poll(ctx, &resp, opts...); err != nil { + return nil, err + } + if !op.Done() { + return nil, nil + } + return &resp, nil +} + +// Metadata returns metadata associated with the long-running operation. +// Metadata itself does not contact the server, but Poll does. +// To get the latest metadata, call this method after a successful call to Poll. +// If the metadata is not available, the returned metadata and error are both nil. +func (op *BatchCreateJobsOperation) Metadata() (*talentpb.BatchOperationMetadata, error) { + var meta talentpb.BatchOperationMetadata + if err := op.lro.Metadata(&meta); err == longrunning.ErrNoMetadata { + return nil, nil + } else if err != nil { + return nil, err + } + return &meta, nil +} + +// Done reports whether the long-running operation has completed. +func (op *BatchCreateJobsOperation) Done() bool { + return op.lro.Done() +} + +// Name returns the name of the long-running operation. +// The name is assigned by the server and is unique within the service from which the operation is created. +func (op *BatchCreateJobsOperation) Name() string { + return op.lro.Name() +} + +// BatchDeleteJobsOperation manages a long-running operation from BatchDeleteJobs. +type BatchDeleteJobsOperation struct { + lro *longrunning.Operation +} + +// BatchDeleteJobsOperation returns a new BatchDeleteJobsOperation from a given name. +// The name must be that of a previously created BatchDeleteJobsOperation, possibly from a different process. +func (c *JobClient) BatchDeleteJobsOperation(name string) *BatchDeleteJobsOperation { + return &BatchDeleteJobsOperation{ + lro: longrunning.InternalNewOperation(c.LROClient, &longrunningpb.Operation{Name: name}), + } +} + +// Wait blocks until the long-running operation is completed, returning the response and any errors encountered. +// +// See documentation of Poll for error-handling information. +func (op *BatchDeleteJobsOperation) Wait(ctx context.Context, opts ...gax.CallOption) (*talentpb.BatchDeleteJobsResponse, error) { + var resp talentpb.BatchDeleteJobsResponse + if err := op.lro.WaitWithInterval(ctx, &resp, time.Minute, opts...); err != nil { + return nil, err + } + return &resp, nil +} + +// Poll fetches the latest state of the long-running operation. +// +// Poll also fetches the latest metadata, which can be retrieved by Metadata. +// +// If Poll fails, the error is returned and op is unmodified. If Poll succeeds and +// the operation has completed with failure, the error is returned and op.Done will return true. +// If Poll succeeds and the operation has completed successfully, +// op.Done will return true, and the response of the operation is returned. +// If Poll succeeds and the operation has not completed, the returned response and error are both nil. +func (op *BatchDeleteJobsOperation) Poll(ctx context.Context, opts ...gax.CallOption) (*talentpb.BatchDeleteJobsResponse, error) { + var resp talentpb.BatchDeleteJobsResponse + if err := op.lro.Poll(ctx, &resp, opts...); err != nil { + return nil, err + } + if !op.Done() { + return nil, nil + } + return &resp, nil +} + +// Metadata returns metadata associated with the long-running operation. +// Metadata itself does not contact the server, but Poll does. +// To get the latest metadata, call this method after a successful call to Poll. +// If the metadata is not available, the returned metadata and error are both nil. +func (op *BatchDeleteJobsOperation) Metadata() (*talentpb.BatchOperationMetadata, error) { + var meta talentpb.BatchOperationMetadata + if err := op.lro.Metadata(&meta); err == longrunning.ErrNoMetadata { + return nil, nil + } else if err != nil { + return nil, err + } + return &meta, nil +} + +// Done reports whether the long-running operation has completed. +func (op *BatchDeleteJobsOperation) Done() bool { + return op.lro.Done() +} + +// Name returns the name of the long-running operation. +// The name is assigned by the server and is unique within the service from which the operation is created. +func (op *BatchDeleteJobsOperation) Name() string { + return op.lro.Name() +} + +// BatchUpdateJobsOperation manages a long-running operation from BatchUpdateJobs. +type BatchUpdateJobsOperation struct { + lro *longrunning.Operation +} + +// BatchUpdateJobsOperation returns a new BatchUpdateJobsOperation from a given name. +// The name must be that of a previously created BatchUpdateJobsOperation, possibly from a different process. +func (c *JobClient) BatchUpdateJobsOperation(name string) *BatchUpdateJobsOperation { + return &BatchUpdateJobsOperation{ + lro: longrunning.InternalNewOperation(c.LROClient, &longrunningpb.Operation{Name: name}), + } +} + +// Wait blocks until the long-running operation is completed, returning the response and any errors encountered. +// +// See documentation of Poll for error-handling information. +func (op *BatchUpdateJobsOperation) Wait(ctx context.Context, opts ...gax.CallOption) (*talentpb.BatchUpdateJobsResponse, error) { + var resp talentpb.BatchUpdateJobsResponse + if err := op.lro.WaitWithInterval(ctx, &resp, time.Minute, opts...); err != nil { + return nil, err + } + return &resp, nil +} + +// Poll fetches the latest state of the long-running operation. +// +// Poll also fetches the latest metadata, which can be retrieved by Metadata. +// +// If Poll fails, the error is returned and op is unmodified. If Poll succeeds and +// the operation has completed with failure, the error is returned and op.Done will return true. +// If Poll succeeds and the operation has completed successfully, +// op.Done will return true, and the response of the operation is returned. +// If Poll succeeds and the operation has not completed, the returned response and error are both nil. +func (op *BatchUpdateJobsOperation) Poll(ctx context.Context, opts ...gax.CallOption) (*talentpb.BatchUpdateJobsResponse, error) { + var resp talentpb.BatchUpdateJobsResponse + if err := op.lro.Poll(ctx, &resp, opts...); err != nil { + return nil, err + } + if !op.Done() { + return nil, nil + } + return &resp, nil +} + +// Metadata returns metadata associated with the long-running operation. +// Metadata itself does not contact the server, but Poll does. +// To get the latest metadata, call this method after a successful call to Poll. +// If the metadata is not available, the returned metadata and error are both nil. +func (op *BatchUpdateJobsOperation) Metadata() (*talentpb.BatchOperationMetadata, error) { + var meta talentpb.BatchOperationMetadata + if err := op.lro.Metadata(&meta); err == longrunning.ErrNoMetadata { + return nil, nil + } else if err != nil { + return nil, err + } + return &meta, nil +} + +// Done reports whether the long-running operation has completed. +func (op *BatchUpdateJobsOperation) Done() bool { + return op.lro.Done() +} + +// Name returns the name of the long-running operation. +// The name is assigned by the server and is unique within the service from which the operation is created. +func (op *BatchUpdateJobsOperation) Name() string { + return op.lro.Name() +} + +// JobIterator manages a stream of *talentpb.Job. +type JobIterator struct { + items []*talentpb.Job + pageInfo *iterator.PageInfo + nextFunc func() error + + // Response is the raw response for the current page. + // It must be cast to the RPC response type. + // Calling Next() or InternalFetch() updates this value. + Response interface{} + + // InternalFetch is for use by the Google Cloud Libraries only. + // It is not part of the stable interface of this package. + // + // InternalFetch returns results from a single call to the underlying RPC. + // The number of results is no greater than pageSize. + // If there are no more results, nextPageToken is empty and err is nil. + InternalFetch func(pageSize int, pageToken string) (results []*talentpb.Job, nextPageToken string, err error) +} + +// PageInfo supports pagination. See the google.golang.org/api/iterator package for details. +func (it *JobIterator) PageInfo() *iterator.PageInfo { + return it.pageInfo +} + +// Next returns the next result. Its second return value is iterator.Done if there are no more +// results. Once Next returns Done, all subsequent calls will return Done. +func (it *JobIterator) Next() (*talentpb.Job, error) { + var item *talentpb.Job + if err := it.nextFunc(); err != nil { + return item, err + } + item = it.items[0] + it.items = it.items[1:] + return item, nil +} + +func (it *JobIterator) bufLen() int { + return len(it.items) +} + +func (it *JobIterator) takeBuf() interface{} { + b := it.items + it.items = nil + return b +} diff --git a/talent/apiv4/job_client_example_test.go b/talent/apiv4/job_client_example_test.go new file mode 100644 index 00000000000..ccbb63dc734 --- /dev/null +++ b/talent/apiv4/job_client_example_test.go @@ -0,0 +1,253 @@ +// Copyright 2020 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by protoc-gen-go_gapic. DO NOT EDIT. + +package talent_test + +import ( + "context" + + talent "cloud.google.com/go/talent/apiv4" + "google.golang.org/api/iterator" + talentpb "google.golang.org/genproto/googleapis/cloud/talent/v4" +) + +func ExampleNewJobClient() { + ctx := context.Background() + c, err := talent.NewJobClient(ctx) + if err != nil { + // TODO: Handle error. + } + // TODO: Use client. + _ = c +} + +func ExampleJobClient_CreateJob() { + // import talentpb "google.golang.org/genproto/googleapis/cloud/talent/v4" + + ctx := context.Background() + c, err := talent.NewJobClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &talentpb.CreateJobRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.CreateJob(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleJobClient_BatchCreateJobs() { + // import talentpb "google.golang.org/genproto/googleapis/cloud/talent/v4" + + ctx := context.Background() + c, err := talent.NewJobClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &talentpb.BatchCreateJobsRequest{ + // TODO: Fill request struct fields. + } + op, err := c.BatchCreateJobs(ctx, req) + if err != nil { + // TODO: Handle error. + } + + resp, err := op.Wait(ctx) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleJobClient_GetJob() { + // import talentpb "google.golang.org/genproto/googleapis/cloud/talent/v4" + + ctx := context.Background() + c, err := talent.NewJobClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &talentpb.GetJobRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.GetJob(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleJobClient_UpdateJob() { + // import talentpb "google.golang.org/genproto/googleapis/cloud/talent/v4" + + ctx := context.Background() + c, err := talent.NewJobClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &talentpb.UpdateJobRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.UpdateJob(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleJobClient_BatchUpdateJobs() { + // import talentpb "google.golang.org/genproto/googleapis/cloud/talent/v4" + + ctx := context.Background() + c, err := talent.NewJobClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &talentpb.BatchUpdateJobsRequest{ + // TODO: Fill request struct fields. + } + op, err := c.BatchUpdateJobs(ctx, req) + if err != nil { + // TODO: Handle error. + } + + resp, err := op.Wait(ctx) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleJobClient_DeleteJob() { + ctx := context.Background() + c, err := talent.NewJobClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &talentpb.DeleteJobRequest{ + // TODO: Fill request struct fields. + } + err = c.DeleteJob(ctx, req) + if err != nil { + // TODO: Handle error. + } +} + +func ExampleJobClient_BatchDeleteJobs() { + // import talentpb "google.golang.org/genproto/googleapis/cloud/talent/v4" + + ctx := context.Background() + c, err := talent.NewJobClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &talentpb.BatchDeleteJobsRequest{ + // TODO: Fill request struct fields. + } + op, err := c.BatchDeleteJobs(ctx, req) + if err != nil { + // TODO: Handle error. + } + + resp, err := op.Wait(ctx) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleJobClient_ListJobs() { + // import talentpb "google.golang.org/genproto/googleapis/cloud/talent/v4" + // import "google.golang.org/api/iterator" + + ctx := context.Background() + c, err := talent.NewJobClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &talentpb.ListJobsRequest{ + // TODO: Fill request struct fields. + } + it := c.ListJobs(ctx, req) + for { + resp, err := it.Next() + if err == iterator.Done { + break + } + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp + } +} + +func ExampleJobClient_SearchJobs() { + // import talentpb "google.golang.org/genproto/googleapis/cloud/talent/v4" + + ctx := context.Background() + c, err := talent.NewJobClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &talentpb.SearchJobsRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.SearchJobs(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleJobClient_SearchJobsForAlert() { + // import talentpb "google.golang.org/genproto/googleapis/cloud/talent/v4" + + ctx := context.Background() + c, err := talent.NewJobClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &talentpb.SearchJobsRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.SearchJobsForAlert(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} diff --git a/talent/apiv4/tenant_client.go b/talent/apiv4/tenant_client.go new file mode 100644 index 00000000000..3ba4595458b --- /dev/null +++ b/talent/apiv4/tenant_client.go @@ -0,0 +1,319 @@ +// Copyright 2020 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by protoc-gen-go_gapic. DO NOT EDIT. + +package talent + +import ( + "context" + "fmt" + "math" + "net/url" + "time" + + "github.com/golang/protobuf/proto" + gax "github.com/googleapis/gax-go/v2" + "google.golang.org/api/iterator" + "google.golang.org/api/option" + gtransport "google.golang.org/api/transport/grpc" + talentpb "google.golang.org/genproto/googleapis/cloud/talent/v4" + "google.golang.org/grpc" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/metadata" +) + +var newTenantClientHook clientHook + +// TenantCallOptions contains the retry settings for each method of TenantClient. +type TenantCallOptions struct { + CreateTenant []gax.CallOption + GetTenant []gax.CallOption + UpdateTenant []gax.CallOption + DeleteTenant []gax.CallOption + ListTenants []gax.CallOption +} + +func defaultTenantClientOptions() []option.ClientOption { + return []option.ClientOption{ + option.WithEndpoint("jobs.googleapis.com:443"), + option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), + option.WithScopes(DefaultAuthScopes()...), + option.WithGRPCDialOption(grpc.WithDefaultCallOptions( + grpc.MaxCallRecvMsgSize(math.MaxInt32))), + } +} + +func defaultTenantCallOptions() *TenantCallOptions { + return &TenantCallOptions{ + CreateTenant: []gax.CallOption{}, + GetTenant: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.DeadlineExceeded, + codes.Unavailable, + }, gax.Backoff{ + Initial: 100 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, + UpdateTenant: []gax.CallOption{}, + DeleteTenant: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.DeadlineExceeded, + codes.Unavailable, + }, gax.Backoff{ + Initial: 100 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, + ListTenants: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.DeadlineExceeded, + codes.Unavailable, + }, gax.Backoff{ + Initial: 100 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, + } +} + +// TenantClient is a client for interacting with . +// +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +type TenantClient struct { + // Connection pool of gRPC connections to the service. + connPool gtransport.ConnPool + + // The gRPC API client. + tenantClient talentpb.TenantServiceClient + + // The call options for this service. + CallOptions *TenantCallOptions + + // The x-goog-* metadata to be sent with each request. + xGoogMetadata metadata.MD +} + +// NewTenantClient creates a new tenant service client. +// +// A service that handles tenant management, including CRUD and enumeration. +func NewTenantClient(ctx context.Context, opts ...option.ClientOption) (*TenantClient, error) { + clientOpts := defaultTenantClientOptions() + + if newTenantClientHook != nil { + hookOpts, err := newTenantClientHook(ctx, clientHookParams{}) + if err != nil { + return nil, err + } + clientOpts = append(clientOpts, hookOpts...) + } + + connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...) + if err != nil { + return nil, err + } + c := &TenantClient{ + connPool: connPool, + CallOptions: defaultTenantCallOptions(), + + tenantClient: talentpb.NewTenantServiceClient(connPool), + } + c.setGoogleClientInfo() + + return c, nil +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *TenantClient) Connection() *grpc.ClientConn { + return c.connPool.Conn() +} + +// Close closes the connection to the API service. The user should invoke this when +// the client is no longer required. +func (c *TenantClient) Close() error { + return c.connPool.Close() +} + +// setGoogleClientInfo sets the name and version of the application in +// the `x-goog-api-client` header passed on each request. Intended for +// use by Google-written clients. +func (c *TenantClient) setGoogleClientInfo(keyval ...string) { + kv := append([]string{"gl-go", versionGo()}, keyval...) + kv = append(kv, "gapic", versionClient, "gax", gax.Version, "grpc", grpc.Version) + c.xGoogMetadata = metadata.Pairs("x-goog-api-client", gax.XGoogHeader(kv...)) +} + +// CreateTenant creates a new tenant entity. +func (c *TenantClient) CreateTenant(ctx context.Context, req *talentpb.CreateTenantRequest, opts ...gax.CallOption) (*talentpb.Tenant, error) { + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append(c.CallOptions.CreateTenant[0:len(c.CallOptions.CreateTenant):len(c.CallOptions.CreateTenant)], opts...) + var resp *talentpb.Tenant + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.tenantClient.CreateTenant(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +// GetTenant retrieves specified tenant. +func (c *TenantClient) GetTenant(ctx context.Context, req *talentpb.GetTenantRequest, opts ...gax.CallOption) (*talentpb.Tenant, error) { + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append(c.CallOptions.GetTenant[0:len(c.CallOptions.GetTenant):len(c.CallOptions.GetTenant)], opts...) + var resp *talentpb.Tenant + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.tenantClient.GetTenant(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +// UpdateTenant updates specified tenant. +func (c *TenantClient) UpdateTenant(ctx context.Context, req *talentpb.UpdateTenantRequest, opts ...gax.CallOption) (*talentpb.Tenant, error) { + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "tenant.name", url.QueryEscape(req.GetTenant().GetName()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append(c.CallOptions.UpdateTenant[0:len(c.CallOptions.UpdateTenant):len(c.CallOptions.UpdateTenant)], opts...) + var resp *talentpb.Tenant + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.tenantClient.UpdateTenant(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +// DeleteTenant deletes specified tenant. +func (c *TenantClient) DeleteTenant(ctx context.Context, req *talentpb.DeleteTenantRequest, opts ...gax.CallOption) error { + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append(c.CallOptions.DeleteTenant[0:len(c.CallOptions.DeleteTenant):len(c.CallOptions.DeleteTenant)], opts...) + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + _, err = c.tenantClient.DeleteTenant(ctx, req, settings.GRPC...) + return err + }, opts...) + return err +} + +// ListTenants lists all tenants associated with the project. +func (c *TenantClient) ListTenants(ctx context.Context, req *talentpb.ListTenantsRequest, opts ...gax.CallOption) *TenantIterator { + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append(c.CallOptions.ListTenants[0:len(c.CallOptions.ListTenants):len(c.CallOptions.ListTenants)], opts...) + it := &TenantIterator{} + req = proto.Clone(req).(*talentpb.ListTenantsRequest) + it.InternalFetch = func(pageSize int, pageToken string) ([]*talentpb.Tenant, string, error) { + var resp *talentpb.ListTenantsResponse + req.PageToken = pageToken + if pageSize > math.MaxInt32 { + req.PageSize = math.MaxInt32 + } else { + req.PageSize = int32(pageSize) + } + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.tenantClient.ListTenants(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, "", err + } + + it.Response = resp + return resp.Tenants, resp.NextPageToken, nil + } + fetch := func(pageSize int, pageToken string) (string, error) { + items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) + if err != nil { + return "", err + } + it.items = append(it.items, items...) + return nextPageToken, nil + } + it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) + it.pageInfo.MaxSize = int(req.PageSize) + it.pageInfo.Token = req.PageToken + return it +} + +// TenantIterator manages a stream of *talentpb.Tenant. +type TenantIterator struct { + items []*talentpb.Tenant + pageInfo *iterator.PageInfo + nextFunc func() error + + // Response is the raw response for the current page. + // It must be cast to the RPC response type. + // Calling Next() or InternalFetch() updates this value. + Response interface{} + + // InternalFetch is for use by the Google Cloud Libraries only. + // It is not part of the stable interface of this package. + // + // InternalFetch returns results from a single call to the underlying RPC. + // The number of results is no greater than pageSize. + // If there are no more results, nextPageToken is empty and err is nil. + InternalFetch func(pageSize int, pageToken string) (results []*talentpb.Tenant, nextPageToken string, err error) +} + +// PageInfo supports pagination. See the google.golang.org/api/iterator package for details. +func (it *TenantIterator) PageInfo() *iterator.PageInfo { + return it.pageInfo +} + +// Next returns the next result. Its second return value is iterator.Done if there are no more +// results. Once Next returns Done, all subsequent calls will return Done. +func (it *TenantIterator) Next() (*talentpb.Tenant, error) { + var item *talentpb.Tenant + if err := it.nextFunc(); err != nil { + return item, err + } + item = it.items[0] + it.items = it.items[1:] + return item, nil +} + +func (it *TenantIterator) bufLen() int { + return len(it.items) +} + +func (it *TenantIterator) takeBuf() interface{} { + b := it.items + it.items = nil + return b +} diff --git a/talent/apiv4/tenant_client_example_test.go b/talent/apiv4/tenant_client_example_test.go new file mode 100644 index 00000000000..fdc06836f27 --- /dev/null +++ b/talent/apiv4/tenant_client_example_test.go @@ -0,0 +1,138 @@ +// Copyright 2020 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by protoc-gen-go_gapic. DO NOT EDIT. + +package talent_test + +import ( + "context" + + talent "cloud.google.com/go/talent/apiv4" + "google.golang.org/api/iterator" + talentpb "google.golang.org/genproto/googleapis/cloud/talent/v4" +) + +func ExampleNewTenantClient() { + ctx := context.Background() + c, err := talent.NewTenantClient(ctx) + if err != nil { + // TODO: Handle error. + } + // TODO: Use client. + _ = c +} + +func ExampleTenantClient_CreateTenant() { + // import talentpb "google.golang.org/genproto/googleapis/cloud/talent/v4" + + ctx := context.Background() + c, err := talent.NewTenantClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &talentpb.CreateTenantRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.CreateTenant(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleTenantClient_GetTenant() { + // import talentpb "google.golang.org/genproto/googleapis/cloud/talent/v4" + + ctx := context.Background() + c, err := talent.NewTenantClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &talentpb.GetTenantRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.GetTenant(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleTenantClient_UpdateTenant() { + // import talentpb "google.golang.org/genproto/googleapis/cloud/talent/v4" + + ctx := context.Background() + c, err := talent.NewTenantClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &talentpb.UpdateTenantRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.UpdateTenant(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleTenantClient_DeleteTenant() { + ctx := context.Background() + c, err := talent.NewTenantClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &talentpb.DeleteTenantRequest{ + // TODO: Fill request struct fields. + } + err = c.DeleteTenant(ctx, req) + if err != nil { + // TODO: Handle error. + } +} + +func ExampleTenantClient_ListTenants() { + // import talentpb "google.golang.org/genproto/googleapis/cloud/talent/v4" + // import "google.golang.org/api/iterator" + + ctx := context.Background() + c, err := talent.NewTenantClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &talentpb.ListTenantsRequest{ + // TODO: Fill request struct fields. + } + it := c.ListTenants(ctx, req) + for { + resp, err := it.Next() + if err == iterator.Done { + break + } + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp + } +}