You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

135 lines
4.3 KiB

  1. // Copyright 2019 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. // Code generated by gapic-generator. DO NOT EDIT.
  15. package talent
  16. import (
  17. "context"
  18. "time"
  19. gax "github.com/googleapis/gax-go/v2"
  20. "google.golang.org/api/option"
  21. "google.golang.org/api/transport"
  22. talentpb "google.golang.org/genproto/googleapis/cloud/talent/v4beta1"
  23. "google.golang.org/grpc"
  24. "google.golang.org/grpc/codes"
  25. "google.golang.org/grpc/metadata"
  26. )
  27. // CompletionCallOptions contains the retry settings for each method of CompletionClient.
  28. type CompletionCallOptions struct {
  29. CompleteQuery []gax.CallOption
  30. }
  31. func defaultCompletionClientOptions() []option.ClientOption {
  32. return []option.ClientOption{
  33. option.WithEndpoint("jobs.googleapis.com:443"),
  34. option.WithScopes(DefaultAuthScopes()...),
  35. }
  36. }
  37. func defaultCompletionCallOptions() *CompletionCallOptions {
  38. retry := map[[2]string][]gax.CallOption{
  39. {"default", "idempotent"}: {
  40. gax.WithRetry(func() gax.Retryer {
  41. return gax.OnCodes([]codes.Code{
  42. codes.DeadlineExceeded,
  43. codes.Unavailable,
  44. }, gax.Backoff{
  45. Initial: 100 * time.Millisecond,
  46. Max: 60000 * time.Millisecond,
  47. Multiplier: 1.3,
  48. })
  49. }),
  50. },
  51. }
  52. return &CompletionCallOptions{
  53. CompleteQuery: retry[[2]string{"default", "idempotent"}],
  54. }
  55. }
  56. // CompletionClient is a client for interacting with Cloud Talent Solution API.
  57. //
  58. // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
  59. type CompletionClient struct {
  60. // The connection to the service.
  61. conn *grpc.ClientConn
  62. // The gRPC API client.
  63. completionClient talentpb.CompletionClient
  64. // The call options for this service.
  65. CallOptions *CompletionCallOptions
  66. // The x-goog-* metadata to be sent with each request.
  67. xGoogMetadata metadata.MD
  68. }
  69. // NewCompletionClient creates a new completion client.
  70. //
  71. // A service handles auto completion.
  72. func NewCompletionClient(ctx context.Context, opts ...option.ClientOption) (*CompletionClient, error) {
  73. conn, err := transport.DialGRPC(ctx, append(defaultCompletionClientOptions(), opts...)...)
  74. if err != nil {
  75. return nil, err
  76. }
  77. c := &CompletionClient{
  78. conn: conn,
  79. CallOptions: defaultCompletionCallOptions(),
  80. completionClient: talentpb.NewCompletionClient(conn),
  81. }
  82. c.setGoogleClientInfo()
  83. return c, nil
  84. }
  85. // Connection returns the client's connection to the API service.
  86. func (c *CompletionClient) Connection() *grpc.ClientConn {
  87. return c.conn
  88. }
  89. // Close closes the connection to the API service. The user should invoke this when
  90. // the client is no longer required.
  91. func (c *CompletionClient) Close() error {
  92. return c.conn.Close()
  93. }
  94. // setGoogleClientInfo sets the name and version of the application in
  95. // the `x-goog-api-client` header passed on each request. Intended for
  96. // use by Google-written clients.
  97. func (c *CompletionClient) setGoogleClientInfo(keyval ...string) {
  98. kv := append([]string{"gl-go", versionGo()}, keyval...)
  99. kv = append(kv, "gapic", versionClient, "gax", gax.Version, "grpc", grpc.Version)
  100. c.xGoogMetadata = metadata.Pairs("x-goog-api-client", gax.XGoogHeader(kv...))
  101. }
  102. // CompleteQuery completes the specified prefix with keyword suggestions.
  103. // Intended for use by a job search auto-complete search box.
  104. func (c *CompletionClient) CompleteQuery(ctx context.Context, req *talentpb.CompleteQueryRequest, opts ...gax.CallOption) (*talentpb.CompleteQueryResponse, error) {
  105. ctx = insertMetadata(ctx, c.xGoogMetadata)
  106. opts = append(c.CallOptions.CompleteQuery[0:len(c.CallOptions.CompleteQuery):len(c.CallOptions.CompleteQuery)], opts...)
  107. var resp *talentpb.CompleteQueryResponse
  108. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  109. var err error
  110. resp, err = c.completionClient.CompleteQuery(ctx, req, settings.GRPC...)
  111. return err
  112. }, opts...)
  113. if err != nil {
  114. return nil, err
  115. }
  116. return resp, nil
  117. }