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	"time"
25
26	gax "github.com/googleapis/gax-go/v2"
27	"google.golang.org/api/option"
28	gtransport "google.golang.org/api/transport/grpc"
29	clouderrorreportingpb "google.golang.org/genproto/googleapis/devtools/clouderrorreporting/v1beta1"
30	"google.golang.org/grpc"
31	"google.golang.org/grpc/codes"
32	"google.golang.org/grpc/metadata"
33)
34
35// ErrorGroupCallOptions contains the retry settings for each method of ErrorGroupClient.
36type ErrorGroupCallOptions struct {
37	GetGroup    []gax.CallOption
38	UpdateGroup []gax.CallOption
39}
40
41func defaultErrorGroupClientOptions() []option.ClientOption {
42	return []option.ClientOption{
43		option.WithEndpoint("clouderrorreporting.googleapis.com:443"),
44		option.WithGRPCDialOption(grpc.WithDisableServiceConfig()),
45		option.WithScopes(DefaultAuthScopes()...),
46		option.WithGRPCDialOption(grpc.WithDefaultCallOptions(
47			grpc.MaxCallRecvMsgSize(math.MaxInt32))),
48	}
49}
50
51func defaultErrorGroupCallOptions() *ErrorGroupCallOptions {
52	return &ErrorGroupCallOptions{
53		GetGroup: []gax.CallOption{
54			gax.WithRetry(func() gax.Retryer {
55				return gax.OnCodes([]codes.Code{
56					codes.Unavailable,
57					codes.DeadlineExceeded,
58				}, gax.Backoff{
59					Initial:    100 * time.Millisecond,
60					Max:        60000 * time.Millisecond,
61					Multiplier: 1.30,
62				})
63			}),
64		},
65		UpdateGroup: []gax.CallOption{
66			gax.WithRetry(func() gax.Retryer {
67				return gax.OnCodes([]codes.Code{
68					codes.Unavailable,
69					codes.DeadlineExceeded,
70				}, gax.Backoff{
71					Initial:    100 * time.Millisecond,
72					Max:        60000 * time.Millisecond,
73					Multiplier: 1.30,
74				})
75			}),
76		},
77	}
78}
79
80// ErrorGroupClient is a client for interacting with Stackdriver Error Reporting API.
81//
82// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
83type ErrorGroupClient struct {
84	// Connection pool of gRPC connections to the service.
85	connPool gtransport.ConnPool
86
87	// The gRPC API client.
88	errorGroupClient clouderrorreportingpb.ErrorGroupServiceClient
89
90	// The call options for this service.
91	CallOptions *ErrorGroupCallOptions
92
93	// The x-goog-* metadata to be sent with each request.
94	xGoogMetadata metadata.MD
95}
96
97// NewErrorGroupClient creates a new error group service client.
98//
99// Service for retrieving and updating individual error groups.
100func NewErrorGroupClient(ctx context.Context, opts ...option.ClientOption) (*ErrorGroupClient, error) {
101	connPool, err := gtransport.DialPool(ctx, append(defaultErrorGroupClientOptions(), opts...)...)
102	if err != nil {
103		return nil, err
104	}
105	c := &ErrorGroupClient{
106		connPool:    connPool,
107		CallOptions: defaultErrorGroupCallOptions(),
108
109		errorGroupClient: clouderrorreportingpb.NewErrorGroupServiceClient(connPool),
110	}
111	c.SetGoogleClientInfo()
112
113	return c, nil
114}
115
116// Connection returns a connection to the API service.
117//
118// Deprecated.
119func (c *ErrorGroupClient) Connection() *grpc.ClientConn {
120	return c.connPool.Conn()
121}
122
123// Close closes the connection to the API service. The user should invoke this when
124// the client is no longer required.
125func (c *ErrorGroupClient) Close() error {
126	return c.connPool.Close()
127}
128
129// SetGoogleClientInfo sets the name and version of the application in
130// the `x-goog-api-client` header passed on each request. Intended for
131// use by Google-written clients.
132func (c *ErrorGroupClient) SetGoogleClientInfo(keyval ...string) {
133	kv := append([]string{"gl-go", versionGo()}, keyval...)
134	kv = append(kv, "gapic", versionClient, "gax", gax.Version, "grpc", grpc.Version)
135	c.xGoogMetadata = metadata.Pairs("x-goog-api-client", gax.XGoogHeader(kv...))
136}
137
138// GetGroup get the specified group.
139func (c *ErrorGroupClient) GetGroup(ctx context.Context, req *clouderrorreportingpb.GetGroupRequest, opts ...gax.CallOption) (*clouderrorreportingpb.ErrorGroup, error) {
140	md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "group_name", url.QueryEscape(req.GetGroupName())))
141	ctx = insertMetadata(ctx, c.xGoogMetadata, md)
142	opts = append(c.CallOptions.GetGroup[0:len(c.CallOptions.GetGroup):len(c.CallOptions.GetGroup)], opts...)
143	var resp *clouderrorreportingpb.ErrorGroup
144	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
145		var err error
146		resp, err = c.errorGroupClient.GetGroup(ctx, req, settings.GRPC...)
147		return err
148	}, opts...)
149	if err != nil {
150		return nil, err
151	}
152	return resp, nil
153}
154
155// UpdateGroup replace the data for the specified group.
156// Fails if the group does not exist.
157func (c *ErrorGroupClient) UpdateGroup(ctx context.Context, req *clouderrorreportingpb.UpdateGroupRequest, opts ...gax.CallOption) (*clouderrorreportingpb.ErrorGroup, error) {
158	md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "group.name", url.QueryEscape(req.GetGroup().GetName())))
159	ctx = insertMetadata(ctx, c.xGoogMetadata, md)
160	opts = append(c.CallOptions.UpdateGroup[0:len(c.CallOptions.UpdateGroup):len(c.CallOptions.UpdateGroup)], opts...)
161	var resp *clouderrorreportingpb.ErrorGroup
162	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
163		var err error
164		resp, err = c.errorGroupClient.UpdateGroup(ctx, req, settings.GRPC...)
165		return err
166	}, opts...)
167	if err != nil {
168		return nil, err
169	}
170	return resp, nil
171}
172