1// Copyright 2020 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 errorreporting
18
19import (
20	"context"
21	"fmt"
22	"math"
23	"net/url"
24
25	gax "github.com/googleapis/gax-go/v2"
26	"google.golang.org/api/option"
27	gtransport "google.golang.org/api/transport/grpc"
28	clouderrorreportingpb "google.golang.org/genproto/googleapis/devtools/clouderrorreporting/v1beta1"
29	"google.golang.org/grpc"
30	"google.golang.org/grpc/metadata"
31)
32
33var newReportErrorsClientHook clientHook
34
35// ReportErrorsCallOptions contains the retry settings for each method of ReportErrorsClient.
36type ReportErrorsCallOptions struct {
37	ReportErrorEvent []gax.CallOption
38}
39
40func defaultReportErrorsClientOptions() []option.ClientOption {
41	return []option.ClientOption{
42		option.WithEndpoint("clouderrorreporting.googleapis.com:443"),
43		option.WithGRPCDialOption(grpc.WithDisableServiceConfig()),
44		option.WithScopes(DefaultAuthScopes()...),
45		option.WithGRPCDialOption(grpc.WithDefaultCallOptions(
46			grpc.MaxCallRecvMsgSize(math.MaxInt32))),
47	}
48}
49
50func defaultReportErrorsCallOptions() *ReportErrorsCallOptions {
51	return &ReportErrorsCallOptions{
52		ReportErrorEvent: []gax.CallOption{},
53	}
54}
55
56// ReportErrorsClient is a client for interacting with Stackdriver Error Reporting API.
57//
58// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
59type ReportErrorsClient struct {
60	// Connection pool of gRPC connections to the service.
61	connPool gtransport.ConnPool
62
63	// The gRPC API client.
64	reportErrorsClient clouderrorreportingpb.ReportErrorsServiceClient
65
66	// The call options for this service.
67	CallOptions *ReportErrorsCallOptions
68
69	// The x-goog-* metadata to be sent with each request.
70	xGoogMetadata metadata.MD
71}
72
73// NewReportErrorsClient creates a new report errors service client.
74//
75// An API for reporting error events.
76func NewReportErrorsClient(ctx context.Context, opts ...option.ClientOption) (*ReportErrorsClient, error) {
77	clientOpts := defaultReportErrorsClientOptions()
78
79	if newReportErrorsClientHook != nil {
80		hookOpts, err := newReportErrorsClientHook(ctx, clientHookParams{})
81		if err != nil {
82			return nil, err
83		}
84		clientOpts = append(clientOpts, hookOpts...)
85	}
86
87	connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...)
88	if err != nil {
89		return nil, err
90	}
91	c := &ReportErrorsClient{
92		connPool:    connPool,
93		CallOptions: defaultReportErrorsCallOptions(),
94
95		reportErrorsClient: clouderrorreportingpb.NewReportErrorsServiceClient(connPool),
96	}
97	c.setGoogleClientInfo()
98
99	return c, nil
100}
101
102// Connection returns a connection to the API service.
103//
104// Deprecated.
105func (c *ReportErrorsClient) Connection() *grpc.ClientConn {
106	return c.connPool.Conn()
107}
108
109// Close closes the connection to the API service. The user should invoke this when
110// the client is no longer required.
111func (c *ReportErrorsClient) Close() error {
112	return c.connPool.Close()
113}
114
115// setGoogleClientInfo sets the name and version of the application in
116// the `x-goog-api-client` header passed on each request. Intended for
117// use by Google-written clients.
118func (c *ReportErrorsClient) setGoogleClientInfo(keyval ...string) {
119	kv := append([]string{"gl-go", versionGo()}, keyval...)
120	kv = append(kv, "gapic", versionClient, "gax", gax.Version, "grpc", grpc.Version)
121	c.xGoogMetadata = metadata.Pairs("x-goog-api-client", gax.XGoogHeader(kv...))
122}
123
124// ReportErrorEvent report an individual error event.
125//
126// This endpoint accepts either an OAuth token,
127// or an API key (at https://support.google.com/cloud/answer/6158862)
128// for authentication. To use an API key, append it to the URL as the value of
129// a key parameter. For example:
130//
131// POST https://clouderrorreporting.googleapis.com/v1beta1/projects/example-project/events:report?key=123ABC456
132func (c *ReportErrorsClient) ReportErrorEvent(ctx context.Context, req *clouderrorreportingpb.ReportErrorEventRequest, opts ...gax.CallOption) (*clouderrorreportingpb.ReportErrorEventResponse, error) {
133	md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "project_name", url.QueryEscape(req.GetProjectName())))
134	ctx = insertMetadata(ctx, c.xGoogMetadata, md)
135	opts = append(c.CallOptions.ReportErrorEvent[0:len(c.CallOptions.ReportErrorEvent):len(c.CallOptions.ReportErrorEvent)], opts...)
136	var resp *clouderrorreportingpb.ReportErrorEventResponse
137	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
138		var err error
139		resp, err = c.reportErrorsClient.ReportErrorEvent(ctx, req, settings.GRPC...)
140		return err
141	}, opts...)
142	if err != nil {
143		return nil, err
144	}
145	return resp, nil
146}
147