1// Copyright 2021 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 17package talent 18 19import ( 20 "context" 21 "fmt" 22 "math" 23 "net/url" 24 "time" 25 26 gax "github.com/googleapis/gax-go/v2" 27 "google.golang.org/api/option" 28 "google.golang.org/api/option/internaloption" 29 gtransport "google.golang.org/api/transport/grpc" 30 talentpb "google.golang.org/genproto/googleapis/cloud/talent/v4beta1" 31 "google.golang.org/grpc" 32 "google.golang.org/grpc/codes" 33 "google.golang.org/grpc/metadata" 34) 35 36var newCompletionClientHook clientHook 37 38// CompletionCallOptions contains the retry settings for each method of CompletionClient. 39type CompletionCallOptions struct { 40 CompleteQuery []gax.CallOption 41} 42 43func defaultCompletionGRPCClientOptions() []option.ClientOption { 44 return []option.ClientOption{ 45 internaloption.WithDefaultEndpoint("jobs.googleapis.com:443"), 46 internaloption.WithDefaultMTLSEndpoint("jobs.mtls.googleapis.com:443"), 47 internaloption.WithDefaultAudience("https://jobs.googleapis.com/"), 48 internaloption.WithDefaultScopes(DefaultAuthScopes()...), 49 internaloption.EnableJwtWithScope(), 50 option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), 51 option.WithGRPCDialOption(grpc.WithDefaultCallOptions( 52 grpc.MaxCallRecvMsgSize(math.MaxInt32))), 53 } 54} 55 56func defaultCompletionCallOptions() *CompletionCallOptions { 57 return &CompletionCallOptions{ 58 CompleteQuery: []gax.CallOption{ 59 gax.WithRetry(func() gax.Retryer { 60 return gax.OnCodes([]codes.Code{ 61 codes.DeadlineExceeded, 62 codes.Unavailable, 63 }, gax.Backoff{ 64 Initial: 100 * time.Millisecond, 65 Max: 60000 * time.Millisecond, 66 Multiplier: 1.30, 67 }) 68 }), 69 }, 70 } 71} 72 73// internalCompletionClient is an interface that defines the methods availaible from Cloud Talent Solution API. 74type internalCompletionClient interface { 75 Close() error 76 setGoogleClientInfo(...string) 77 Connection() *grpc.ClientConn 78 CompleteQuery(context.Context, *talentpb.CompleteQueryRequest, ...gax.CallOption) (*talentpb.CompleteQueryResponse, error) 79} 80 81// CompletionClient is a client for interacting with Cloud Talent Solution API. 82// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. 83// 84// A service handles auto completion. 85type CompletionClient struct { 86 // The internal transport-dependent client. 87 internalClient internalCompletionClient 88 89 // The call options for this service. 90 CallOptions *CompletionCallOptions 91} 92 93// Wrapper methods routed to the internal client. 94 95// Close closes the connection to the API service. The user should invoke this when 96// the client is no longer required. 97func (c *CompletionClient) Close() error { 98 return c.internalClient.Close() 99} 100 101// setGoogleClientInfo sets the name and version of the application in 102// the `x-goog-api-client` header passed on each request. Intended for 103// use by Google-written clients. 104func (c *CompletionClient) setGoogleClientInfo(keyval ...string) { 105 c.internalClient.setGoogleClientInfo(keyval...) 106} 107 108// Connection returns a connection to the API service. 109// 110// Deprecated. 111func (c *CompletionClient) Connection() *grpc.ClientConn { 112 return c.internalClient.Connection() 113} 114 115// CompleteQuery completes the specified prefix with keyword suggestions. 116// Intended for use by a job search auto-complete search box. 117func (c *CompletionClient) CompleteQuery(ctx context.Context, req *talentpb.CompleteQueryRequest, opts ...gax.CallOption) (*talentpb.CompleteQueryResponse, error) { 118 return c.internalClient.CompleteQuery(ctx, req, opts...) 119} 120 121// completionGRPCClient is a client for interacting with Cloud Talent Solution API over gRPC transport. 122// 123// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. 124type completionGRPCClient struct { 125 // Connection pool of gRPC connections to the service. 126 connPool gtransport.ConnPool 127 128 // flag to opt out of default deadlines via GOOGLE_API_GO_EXPERIMENTAL_DISABLE_DEFAULT_DEADLINE 129 disableDeadlines bool 130 131 // Points back to the CallOptions field of the containing CompletionClient 132 CallOptions **CompletionCallOptions 133 134 // The gRPC API client. 135 completionClient talentpb.CompletionClient 136 137 // The x-goog-* metadata to be sent with each request. 138 xGoogMetadata metadata.MD 139} 140 141// NewCompletionClient creates a new completion client based on gRPC. 142// The returned client must be Closed when it is done being used to clean up its underlying connections. 143// 144// A service handles auto completion. 145func NewCompletionClient(ctx context.Context, opts ...option.ClientOption) (*CompletionClient, error) { 146 clientOpts := defaultCompletionGRPCClientOptions() 147 if newCompletionClientHook != nil { 148 hookOpts, err := newCompletionClientHook(ctx, clientHookParams{}) 149 if err != nil { 150 return nil, err 151 } 152 clientOpts = append(clientOpts, hookOpts...) 153 } 154 155 disableDeadlines, err := checkDisableDeadlines() 156 if err != nil { 157 return nil, err 158 } 159 160 connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...) 161 if err != nil { 162 return nil, err 163 } 164 client := CompletionClient{CallOptions: defaultCompletionCallOptions()} 165 166 c := &completionGRPCClient{ 167 connPool: connPool, 168 disableDeadlines: disableDeadlines, 169 completionClient: talentpb.NewCompletionClient(connPool), 170 CallOptions: &client.CallOptions, 171 } 172 c.setGoogleClientInfo() 173 174 client.internalClient = c 175 176 return &client, nil 177} 178 179// Connection returns a connection to the API service. 180// 181// Deprecated. 182func (c *completionGRPCClient) Connection() *grpc.ClientConn { 183 return c.connPool.Conn() 184} 185 186// setGoogleClientInfo sets the name and version of the application in 187// the `x-goog-api-client` header passed on each request. Intended for 188// use by Google-written clients. 189func (c *completionGRPCClient) setGoogleClientInfo(keyval ...string) { 190 kv := append([]string{"gl-go", versionGo()}, keyval...) 191 kv = append(kv, "gapic", versionClient, "gax", gax.Version, "grpc", grpc.Version) 192 c.xGoogMetadata = metadata.Pairs("x-goog-api-client", gax.XGoogHeader(kv...)) 193} 194 195// Close closes the connection to the API service. The user should invoke this when 196// the client is no longer required. 197func (c *completionGRPCClient) Close() error { 198 return c.connPool.Close() 199} 200 201func (c *completionGRPCClient) CompleteQuery(ctx context.Context, req *talentpb.CompleteQueryRequest, opts ...gax.CallOption) (*talentpb.CompleteQueryResponse, error) { 202 if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { 203 cctx, cancel := context.WithTimeout(ctx, 30000*time.Millisecond) 204 defer cancel() 205 ctx = cctx 206 } 207 md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))) 208 ctx = insertMetadata(ctx, c.xGoogMetadata, md) 209 opts = append((*c.CallOptions).CompleteQuery[0:len((*c.CallOptions).CompleteQuery):len((*c.CallOptions).CompleteQuery)], opts...) 210 var resp *talentpb.CompleteQueryResponse 211 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 212 var err error 213 resp, err = c.completionClient.CompleteQuery(ctx, req, settings.GRPC...) 214 return err 215 }, opts...) 216 if err != nil { 217 return nil, err 218 } 219 return resp, nil 220} 221