Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.
 
 
 

126 рядки
4.5 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 errorreporting
  16. import (
  17. "context"
  18. gax "github.com/googleapis/gax-go/v2"
  19. "google.golang.org/api/option"
  20. "google.golang.org/api/transport"
  21. clouderrorreportingpb "google.golang.org/genproto/googleapis/devtools/clouderrorreporting/v1beta1"
  22. "google.golang.org/grpc"
  23. "google.golang.org/grpc/metadata"
  24. )
  25. // ReportErrorsCallOptions contains the retry settings for each method of ReportErrorsClient.
  26. type ReportErrorsCallOptions struct {
  27. ReportErrorEvent []gax.CallOption
  28. }
  29. func defaultReportErrorsClientOptions() []option.ClientOption {
  30. return []option.ClientOption{
  31. option.WithEndpoint("clouderrorreporting.googleapis.com:443"),
  32. option.WithScopes(DefaultAuthScopes()...),
  33. }
  34. }
  35. func defaultReportErrorsCallOptions() *ReportErrorsCallOptions {
  36. retry := map[[2]string][]gax.CallOption{}
  37. return &ReportErrorsCallOptions{
  38. ReportErrorEvent: retry[[2]string{"default", "non_idempotent"}],
  39. }
  40. }
  41. // ReportErrorsClient is a client for interacting with Stackdriver Error Reporting API.
  42. //
  43. // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
  44. type ReportErrorsClient struct {
  45. // The connection to the service.
  46. conn *grpc.ClientConn
  47. // The gRPC API client.
  48. reportErrorsClient clouderrorreportingpb.ReportErrorsServiceClient
  49. // The call options for this service.
  50. CallOptions *ReportErrorsCallOptions
  51. // The x-goog-* metadata to be sent with each request.
  52. xGoogMetadata metadata.MD
  53. }
  54. // NewReportErrorsClient creates a new report errors service client.
  55. //
  56. // An API for reporting error events.
  57. func NewReportErrorsClient(ctx context.Context, opts ...option.ClientOption) (*ReportErrorsClient, error) {
  58. conn, err := transport.DialGRPC(ctx, append(defaultReportErrorsClientOptions(), opts...)...)
  59. if err != nil {
  60. return nil, err
  61. }
  62. c := &ReportErrorsClient{
  63. conn: conn,
  64. CallOptions: defaultReportErrorsCallOptions(),
  65. reportErrorsClient: clouderrorreportingpb.NewReportErrorsServiceClient(conn),
  66. }
  67. c.SetGoogleClientInfo()
  68. return c, nil
  69. }
  70. // Connection returns the client's connection to the API service.
  71. func (c *ReportErrorsClient) Connection() *grpc.ClientConn {
  72. return c.conn
  73. }
  74. // Close closes the connection to the API service. The user should invoke this when
  75. // the client is no longer required.
  76. func (c *ReportErrorsClient) Close() error {
  77. return c.conn.Close()
  78. }
  79. // SetGoogleClientInfo sets the name and version of the application in
  80. // the `x-goog-api-client` header passed on each request. Intended for
  81. // use by Google-written clients.
  82. func (c *ReportErrorsClient) SetGoogleClientInfo(keyval ...string) {
  83. kv := append([]string{"gl-go", versionGo()}, keyval...)
  84. kv = append(kv, "gapic", versionClient, "gax", gax.Version, "grpc", grpc.Version)
  85. c.xGoogMetadata = metadata.Pairs("x-goog-api-client", gax.XGoogHeader(kv...))
  86. }
  87. // ReportErrorEvent report an individual error event.
  88. //
  89. // This endpoint accepts <strong>either</strong> an OAuth token,
  90. // <strong>or</strong> an
  91. // <a href="https://support.google.com/cloud/answer/6158862">API key</a>
  92. // for authentication. To use an API key, append it to the URL as the value of
  93. // a key parameter. For example:<pre>POST
  94. // https://clouderrorreporting.googleapis.com/v1beta1/projects/example-project/events:report?key=123ABC456</pre>
  95. func (c *ReportErrorsClient) ReportErrorEvent(ctx context.Context, req *clouderrorreportingpb.ReportErrorEventRequest, opts ...gax.CallOption) (*clouderrorreportingpb.ReportErrorEventResponse, error) {
  96. ctx = insertMetadata(ctx, c.xGoogMetadata)
  97. opts = append(c.CallOptions.ReportErrorEvent[0:len(c.CallOptions.ReportErrorEvent):len(c.CallOptions.ReportErrorEvent)], opts...)
  98. var resp *clouderrorreportingpb.ReportErrorEventResponse
  99. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  100. var err error
  101. resp, err = c.reportErrorsClient.ReportErrorEvent(ctx, req, settings.GRPC...)
  102. return err
  103. }, opts...)
  104. if err != nil {
  105. return nil, err
  106. }
  107. return resp, nil
  108. }