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.
 
 
 

269 lines
9.2 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. "math"
  19. "time"
  20. "github.com/golang/protobuf/proto"
  21. gax "github.com/googleapis/gax-go/v2"
  22. "google.golang.org/api/iterator"
  23. "google.golang.org/api/option"
  24. "google.golang.org/api/transport"
  25. talentpb "google.golang.org/genproto/googleapis/cloud/talent/v4beta1"
  26. "google.golang.org/grpc"
  27. "google.golang.org/grpc/codes"
  28. "google.golang.org/grpc/metadata"
  29. )
  30. // CompanyCallOptions contains the retry settings for each method of CompanyClient.
  31. type CompanyCallOptions struct {
  32. CreateCompany []gax.CallOption
  33. GetCompany []gax.CallOption
  34. UpdateCompany []gax.CallOption
  35. DeleteCompany []gax.CallOption
  36. ListCompanies []gax.CallOption
  37. }
  38. func defaultCompanyClientOptions() []option.ClientOption {
  39. return []option.ClientOption{
  40. option.WithEndpoint("jobs.googleapis.com:443"),
  41. option.WithScopes(DefaultAuthScopes()...),
  42. }
  43. }
  44. func defaultCompanyCallOptions() *CompanyCallOptions {
  45. retry := map[[2]string][]gax.CallOption{
  46. {"default", "idempotent"}: {
  47. gax.WithRetry(func() gax.Retryer {
  48. return gax.OnCodes([]codes.Code{
  49. codes.DeadlineExceeded,
  50. codes.Unavailable,
  51. }, gax.Backoff{
  52. Initial: 100 * time.Millisecond,
  53. Max: 60000 * time.Millisecond,
  54. Multiplier: 1.3,
  55. })
  56. }),
  57. },
  58. }
  59. return &CompanyCallOptions{
  60. CreateCompany: retry[[2]string{"default", "non_idempotent"}],
  61. GetCompany: retry[[2]string{"default", "idempotent"}],
  62. UpdateCompany: retry[[2]string{"default", "non_idempotent"}],
  63. DeleteCompany: retry[[2]string{"default", "idempotent"}],
  64. ListCompanies: retry[[2]string{"default", "idempotent"}],
  65. }
  66. }
  67. // CompanyClient is a client for interacting with Cloud Talent Solution API.
  68. //
  69. // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
  70. type CompanyClient struct {
  71. // The connection to the service.
  72. conn *grpc.ClientConn
  73. // The gRPC API client.
  74. companyClient talentpb.CompanyServiceClient
  75. // The call options for this service.
  76. CallOptions *CompanyCallOptions
  77. // The x-goog-* metadata to be sent with each request.
  78. xGoogMetadata metadata.MD
  79. }
  80. // NewCompanyClient creates a new company service client.
  81. //
  82. // A service that handles company management, including CRUD and enumeration.
  83. func NewCompanyClient(ctx context.Context, opts ...option.ClientOption) (*CompanyClient, error) {
  84. conn, err := transport.DialGRPC(ctx, append(defaultCompanyClientOptions(), opts...)...)
  85. if err != nil {
  86. return nil, err
  87. }
  88. c := &CompanyClient{
  89. conn: conn,
  90. CallOptions: defaultCompanyCallOptions(),
  91. companyClient: talentpb.NewCompanyServiceClient(conn),
  92. }
  93. c.setGoogleClientInfo()
  94. return c, nil
  95. }
  96. // Connection returns the client's connection to the API service.
  97. func (c *CompanyClient) Connection() *grpc.ClientConn {
  98. return c.conn
  99. }
  100. // Close closes the connection to the API service. The user should invoke this when
  101. // the client is no longer required.
  102. func (c *CompanyClient) Close() error {
  103. return c.conn.Close()
  104. }
  105. // setGoogleClientInfo sets the name and version of the application in
  106. // the `x-goog-api-client` header passed on each request. Intended for
  107. // use by Google-written clients.
  108. func (c *CompanyClient) setGoogleClientInfo(keyval ...string) {
  109. kv := append([]string{"gl-go", versionGo()}, keyval...)
  110. kv = append(kv, "gapic", versionClient, "gax", gax.Version, "grpc", grpc.Version)
  111. c.xGoogMetadata = metadata.Pairs("x-goog-api-client", gax.XGoogHeader(kv...))
  112. }
  113. // CreateCompany creates a new company entity.
  114. func (c *CompanyClient) CreateCompany(ctx context.Context, req *talentpb.CreateCompanyRequest, opts ...gax.CallOption) (*talentpb.Company, error) {
  115. ctx = insertMetadata(ctx, c.xGoogMetadata)
  116. opts = append(c.CallOptions.CreateCompany[0:len(c.CallOptions.CreateCompany):len(c.CallOptions.CreateCompany)], opts...)
  117. var resp *talentpb.Company
  118. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  119. var err error
  120. resp, err = c.companyClient.CreateCompany(ctx, req, settings.GRPC...)
  121. return err
  122. }, opts...)
  123. if err != nil {
  124. return nil, err
  125. }
  126. return resp, nil
  127. }
  128. // GetCompany retrieves specified company.
  129. func (c *CompanyClient) GetCompany(ctx context.Context, req *talentpb.GetCompanyRequest, opts ...gax.CallOption) (*talentpb.Company, error) {
  130. ctx = insertMetadata(ctx, c.xGoogMetadata)
  131. opts = append(c.CallOptions.GetCompany[0:len(c.CallOptions.GetCompany):len(c.CallOptions.GetCompany)], opts...)
  132. var resp *talentpb.Company
  133. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  134. var err error
  135. resp, err = c.companyClient.GetCompany(ctx, req, settings.GRPC...)
  136. return err
  137. }, opts...)
  138. if err != nil {
  139. return nil, err
  140. }
  141. return resp, nil
  142. }
  143. // UpdateCompany updates specified company.
  144. func (c *CompanyClient) UpdateCompany(ctx context.Context, req *talentpb.UpdateCompanyRequest, opts ...gax.CallOption) (*talentpb.Company, error) {
  145. ctx = insertMetadata(ctx, c.xGoogMetadata)
  146. opts = append(c.CallOptions.UpdateCompany[0:len(c.CallOptions.UpdateCompany):len(c.CallOptions.UpdateCompany)], opts...)
  147. var resp *talentpb.Company
  148. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  149. var err error
  150. resp, err = c.companyClient.UpdateCompany(ctx, req, settings.GRPC...)
  151. return err
  152. }, opts...)
  153. if err != nil {
  154. return nil, err
  155. }
  156. return resp, nil
  157. }
  158. // DeleteCompany deletes specified company.
  159. // Prerequisite: The company has no jobs associated with it.
  160. func (c *CompanyClient) DeleteCompany(ctx context.Context, req *talentpb.DeleteCompanyRequest, opts ...gax.CallOption) error {
  161. ctx = insertMetadata(ctx, c.xGoogMetadata)
  162. opts = append(c.CallOptions.DeleteCompany[0:len(c.CallOptions.DeleteCompany):len(c.CallOptions.DeleteCompany)], opts...)
  163. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  164. var err error
  165. _, err = c.companyClient.DeleteCompany(ctx, req, settings.GRPC...)
  166. return err
  167. }, opts...)
  168. return err
  169. }
  170. // ListCompanies lists all companies associated with the project.
  171. func (c *CompanyClient) ListCompanies(ctx context.Context, req *talentpb.ListCompaniesRequest, opts ...gax.CallOption) *CompanyIterator {
  172. ctx = insertMetadata(ctx, c.xGoogMetadata)
  173. opts = append(c.CallOptions.ListCompanies[0:len(c.CallOptions.ListCompanies):len(c.CallOptions.ListCompanies)], opts...)
  174. it := &CompanyIterator{}
  175. req = proto.Clone(req).(*talentpb.ListCompaniesRequest)
  176. it.InternalFetch = func(pageSize int, pageToken string) ([]*talentpb.Company, string, error) {
  177. var resp *talentpb.ListCompaniesResponse
  178. req.PageToken = pageToken
  179. if pageSize > math.MaxInt32 {
  180. req.PageSize = math.MaxInt32
  181. } else {
  182. req.PageSize = int32(pageSize)
  183. }
  184. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  185. var err error
  186. resp, err = c.companyClient.ListCompanies(ctx, req, settings.GRPC...)
  187. return err
  188. }, opts...)
  189. if err != nil {
  190. return nil, "", err
  191. }
  192. return resp.Companies, resp.NextPageToken, nil
  193. }
  194. fetch := func(pageSize int, pageToken string) (string, error) {
  195. items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
  196. if err != nil {
  197. return "", err
  198. }
  199. it.items = append(it.items, items...)
  200. return nextPageToken, nil
  201. }
  202. it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
  203. it.pageInfo.MaxSize = int(req.PageSize)
  204. return it
  205. }
  206. // CompanyIterator manages a stream of *talentpb.Company.
  207. type CompanyIterator struct {
  208. items []*talentpb.Company
  209. pageInfo *iterator.PageInfo
  210. nextFunc func() error
  211. // InternalFetch is for use by the Google Cloud Libraries only.
  212. // It is not part of the stable interface of this package.
  213. //
  214. // InternalFetch returns results from a single call to the underlying RPC.
  215. // The number of results is no greater than pageSize.
  216. // If there are no more results, nextPageToken is empty and err is nil.
  217. InternalFetch func(pageSize int, pageToken string) (results []*talentpb.Company, nextPageToken string, err error)
  218. }
  219. // PageInfo supports pagination. See the google.golang.org/api/iterator package for details.
  220. func (it *CompanyIterator) PageInfo() *iterator.PageInfo {
  221. return it.pageInfo
  222. }
  223. // Next returns the next result. Its second return value is iterator.Done if there are no more
  224. // results. Once Next returns Done, all subsequent calls will return Done.
  225. func (it *CompanyIterator) Next() (*talentpb.Company, error) {
  226. var item *talentpb.Company
  227. if err := it.nextFunc(); err != nil {
  228. return item, err
  229. }
  230. item = it.items[0]
  231. it.items = it.items[1:]
  232. return item, nil
  233. }
  234. func (it *CompanyIterator) bufLen() int {
  235. return len(it.items)
  236. }
  237. func (it *CompanyIterator) takeBuf() interface{} {
  238. b := it.items
  239. it.items = nil
  240. return b
  241. }