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.
 
 
 

279 lines
11 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 dialogflow
  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. dialogflowpb "google.golang.org/genproto/googleapis/cloud/dialogflow/v2"
  26. "google.golang.org/grpc"
  27. "google.golang.org/grpc/codes"
  28. "google.golang.org/grpc/metadata"
  29. )
  30. // SessionEntityTypesCallOptions contains the retry settings for each method of SessionEntityTypesClient.
  31. type SessionEntityTypesCallOptions struct {
  32. ListSessionEntityTypes []gax.CallOption
  33. GetSessionEntityType []gax.CallOption
  34. CreateSessionEntityType []gax.CallOption
  35. UpdateSessionEntityType []gax.CallOption
  36. DeleteSessionEntityType []gax.CallOption
  37. }
  38. func defaultSessionEntityTypesClientOptions() []option.ClientOption {
  39. return []option.ClientOption{
  40. option.WithEndpoint("dialogflow.googleapis.com:443"),
  41. option.WithScopes(DefaultAuthScopes()...),
  42. }
  43. }
  44. func defaultSessionEntityTypesCallOptions() *SessionEntityTypesCallOptions {
  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 &SessionEntityTypesCallOptions{
  60. ListSessionEntityTypes: retry[[2]string{"default", "idempotent"}],
  61. GetSessionEntityType: retry[[2]string{"default", "idempotent"}],
  62. CreateSessionEntityType: retry[[2]string{"default", "non_idempotent"}],
  63. UpdateSessionEntityType: retry[[2]string{"default", "non_idempotent"}],
  64. DeleteSessionEntityType: retry[[2]string{"default", "idempotent"}],
  65. }
  66. }
  67. // SessionEntityTypesClient is a client for interacting with Dialogflow API.
  68. //
  69. // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
  70. type SessionEntityTypesClient struct {
  71. // The connection to the service.
  72. conn *grpc.ClientConn
  73. // The gRPC API client.
  74. sessionEntityTypesClient dialogflowpb.SessionEntityTypesClient
  75. // The call options for this service.
  76. CallOptions *SessionEntityTypesCallOptions
  77. // The x-goog-* metadata to be sent with each request.
  78. xGoogMetadata metadata.MD
  79. }
  80. // NewSessionEntityTypesClient creates a new session entity types client.
  81. //
  82. // Entities are extracted from user input and represent parameters that are
  83. // meaningful to your application. For example, a date range, a proper name
  84. // such as a geographic location or landmark, and so on. Entities represent
  85. // actionable data for your application.
  86. //
  87. // Session entity types are referred to as **User** entity types and are
  88. // entities that are built for an individual user such as
  89. // favorites, preferences, playlists, and so on. You can redefine a session
  90. // entity type at the session level.
  91. //
  92. // For more information about entity types, see the
  93. // [Dialogflow documentation](https://dialogflow.com/docs/entities).
  94. func NewSessionEntityTypesClient(ctx context.Context, opts ...option.ClientOption) (*SessionEntityTypesClient, error) {
  95. conn, err := transport.DialGRPC(ctx, append(defaultSessionEntityTypesClientOptions(), opts...)...)
  96. if err != nil {
  97. return nil, err
  98. }
  99. c := &SessionEntityTypesClient{
  100. conn: conn,
  101. CallOptions: defaultSessionEntityTypesCallOptions(),
  102. sessionEntityTypesClient: dialogflowpb.NewSessionEntityTypesClient(conn),
  103. }
  104. c.setGoogleClientInfo()
  105. return c, nil
  106. }
  107. // Connection returns the client's connection to the API service.
  108. func (c *SessionEntityTypesClient) Connection() *grpc.ClientConn {
  109. return c.conn
  110. }
  111. // Close closes the connection to the API service. The user should invoke this when
  112. // the client is no longer required.
  113. func (c *SessionEntityTypesClient) Close() error {
  114. return c.conn.Close()
  115. }
  116. // setGoogleClientInfo sets the name and version of the application in
  117. // the `x-goog-api-client` header passed on each request. Intended for
  118. // use by Google-written clients.
  119. func (c *SessionEntityTypesClient) setGoogleClientInfo(keyval ...string) {
  120. kv := append([]string{"gl-go", versionGo()}, keyval...)
  121. kv = append(kv, "gapic", versionClient, "gax", gax.Version, "grpc", grpc.Version)
  122. c.xGoogMetadata = metadata.Pairs("x-goog-api-client", gax.XGoogHeader(kv...))
  123. }
  124. // ListSessionEntityTypes returns the list of all session entity types in the specified session.
  125. func (c *SessionEntityTypesClient) ListSessionEntityTypes(ctx context.Context, req *dialogflowpb.ListSessionEntityTypesRequest, opts ...gax.CallOption) *SessionEntityTypeIterator {
  126. ctx = insertMetadata(ctx, c.xGoogMetadata)
  127. opts = append(c.CallOptions.ListSessionEntityTypes[0:len(c.CallOptions.ListSessionEntityTypes):len(c.CallOptions.ListSessionEntityTypes)], opts...)
  128. it := &SessionEntityTypeIterator{}
  129. req = proto.Clone(req).(*dialogflowpb.ListSessionEntityTypesRequest)
  130. it.InternalFetch = func(pageSize int, pageToken string) ([]*dialogflowpb.SessionEntityType, string, error) {
  131. var resp *dialogflowpb.ListSessionEntityTypesResponse
  132. req.PageToken = pageToken
  133. if pageSize > math.MaxInt32 {
  134. req.PageSize = math.MaxInt32
  135. } else {
  136. req.PageSize = int32(pageSize)
  137. }
  138. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  139. var err error
  140. resp, err = c.sessionEntityTypesClient.ListSessionEntityTypes(ctx, req, settings.GRPC...)
  141. return err
  142. }, opts...)
  143. if err != nil {
  144. return nil, "", err
  145. }
  146. return resp.SessionEntityTypes, resp.NextPageToken, nil
  147. }
  148. fetch := func(pageSize int, pageToken string) (string, error) {
  149. items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
  150. if err != nil {
  151. return "", err
  152. }
  153. it.items = append(it.items, items...)
  154. return nextPageToken, nil
  155. }
  156. it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
  157. it.pageInfo.MaxSize = int(req.PageSize)
  158. return it
  159. }
  160. // GetSessionEntityType retrieves the specified session entity type.
  161. func (c *SessionEntityTypesClient) GetSessionEntityType(ctx context.Context, req *dialogflowpb.GetSessionEntityTypeRequest, opts ...gax.CallOption) (*dialogflowpb.SessionEntityType, error) {
  162. ctx = insertMetadata(ctx, c.xGoogMetadata)
  163. opts = append(c.CallOptions.GetSessionEntityType[0:len(c.CallOptions.GetSessionEntityType):len(c.CallOptions.GetSessionEntityType)], opts...)
  164. var resp *dialogflowpb.SessionEntityType
  165. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  166. var err error
  167. resp, err = c.sessionEntityTypesClient.GetSessionEntityType(ctx, req, settings.GRPC...)
  168. return err
  169. }, opts...)
  170. if err != nil {
  171. return nil, err
  172. }
  173. return resp, nil
  174. }
  175. // CreateSessionEntityType creates a session entity type.
  176. func (c *SessionEntityTypesClient) CreateSessionEntityType(ctx context.Context, req *dialogflowpb.CreateSessionEntityTypeRequest, opts ...gax.CallOption) (*dialogflowpb.SessionEntityType, error) {
  177. ctx = insertMetadata(ctx, c.xGoogMetadata)
  178. opts = append(c.CallOptions.CreateSessionEntityType[0:len(c.CallOptions.CreateSessionEntityType):len(c.CallOptions.CreateSessionEntityType)], opts...)
  179. var resp *dialogflowpb.SessionEntityType
  180. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  181. var err error
  182. resp, err = c.sessionEntityTypesClient.CreateSessionEntityType(ctx, req, settings.GRPC...)
  183. return err
  184. }, opts...)
  185. if err != nil {
  186. return nil, err
  187. }
  188. return resp, nil
  189. }
  190. // UpdateSessionEntityType updates the specified session entity type.
  191. func (c *SessionEntityTypesClient) UpdateSessionEntityType(ctx context.Context, req *dialogflowpb.UpdateSessionEntityTypeRequest, opts ...gax.CallOption) (*dialogflowpb.SessionEntityType, error) {
  192. ctx = insertMetadata(ctx, c.xGoogMetadata)
  193. opts = append(c.CallOptions.UpdateSessionEntityType[0:len(c.CallOptions.UpdateSessionEntityType):len(c.CallOptions.UpdateSessionEntityType)], opts...)
  194. var resp *dialogflowpb.SessionEntityType
  195. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  196. var err error
  197. resp, err = c.sessionEntityTypesClient.UpdateSessionEntityType(ctx, req, settings.GRPC...)
  198. return err
  199. }, opts...)
  200. if err != nil {
  201. return nil, err
  202. }
  203. return resp, nil
  204. }
  205. // DeleteSessionEntityType deletes the specified session entity type.
  206. func (c *SessionEntityTypesClient) DeleteSessionEntityType(ctx context.Context, req *dialogflowpb.DeleteSessionEntityTypeRequest, opts ...gax.CallOption) error {
  207. ctx = insertMetadata(ctx, c.xGoogMetadata)
  208. opts = append(c.CallOptions.DeleteSessionEntityType[0:len(c.CallOptions.DeleteSessionEntityType):len(c.CallOptions.DeleteSessionEntityType)], opts...)
  209. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  210. var err error
  211. _, err = c.sessionEntityTypesClient.DeleteSessionEntityType(ctx, req, settings.GRPC...)
  212. return err
  213. }, opts...)
  214. return err
  215. }
  216. // SessionEntityTypeIterator manages a stream of *dialogflowpb.SessionEntityType.
  217. type SessionEntityTypeIterator struct {
  218. items []*dialogflowpb.SessionEntityType
  219. pageInfo *iterator.PageInfo
  220. nextFunc func() error
  221. // InternalFetch is for use by the Google Cloud Libraries only.
  222. // It is not part of the stable interface of this package.
  223. //
  224. // InternalFetch returns results from a single call to the underlying RPC.
  225. // The number of results is no greater than pageSize.
  226. // If there are no more results, nextPageToken is empty and err is nil.
  227. InternalFetch func(pageSize int, pageToken string) (results []*dialogflowpb.SessionEntityType, nextPageToken string, err error)
  228. }
  229. // PageInfo supports pagination. See the google.golang.org/api/iterator package for details.
  230. func (it *SessionEntityTypeIterator) PageInfo() *iterator.PageInfo {
  231. return it.pageInfo
  232. }
  233. // Next returns the next result. Its second return value is iterator.Done if there are no more
  234. // results. Once Next returns Done, all subsequent calls will return Done.
  235. func (it *SessionEntityTypeIterator) Next() (*dialogflowpb.SessionEntityType, error) {
  236. var item *dialogflowpb.SessionEntityType
  237. if err := it.nextFunc(); err != nil {
  238. return item, err
  239. }
  240. item = it.items[0]
  241. it.items = it.items[1:]
  242. return item, nil
  243. }
  244. func (it *SessionEntityTypeIterator) bufLen() int {
  245. return len(it.items)
  246. }
  247. func (it *SessionEntityTypeIterator) takeBuf() interface{} {
  248. b := it.items
  249. it.items = nil
  250. return b
  251. }