Source File
metrics_client.go
Belonging Package
cloud.google.com/go/logging/apiv2
type MetricsCallOptions struct {
ListLogMetrics []gax.CallOption
GetLogMetric []gax.CallOption
CreateLogMetric []gax.CallOption
UpdateLogMetric []gax.CallOption
DeleteLogMetric []gax.CallOption
}
func () []option.ClientOption {
return []option.ClientOption{
option.WithEndpoint("logging.googleapis.com:443"),
option.WithScopes(DefaultAuthScopes()...),
}
}
func () *MetricsCallOptions {
:= map[[2]string][]gax.CallOption{
{"default", "idempotent"}: {
gax.WithRetry(func() gax.Retryer {
return gax.OnCodes([]codes.Code{
codes.DeadlineExceeded,
codes.Internal,
codes.Unavailable,
}, gax.Backoff{
Initial: 100 * time.Millisecond,
Max: 60000 * time.Millisecond,
Multiplier: 1.3,
})
}),
},
}
return &MetricsCallOptions{
ListLogMetrics: [[2]string{"default", "idempotent"}],
GetLogMetric: [[2]string{"default", "idempotent"}],
CreateLogMetric: [[2]string{"default", "non_idempotent"}],
UpdateLogMetric: [[2]string{"default", "idempotent"}],
DeleteLogMetric: [[2]string{"default", "idempotent"}],
}
}
func ( context.Context, ...option.ClientOption) (*MetricsClient, error) {
, := transport.DialGRPC(, append(defaultMetricsClientOptions(), ...)...)
if != nil {
return nil,
}
:= &MetricsClient{
conn: ,
CallOptions: defaultMetricsCallOptions(),
metricsClient: loggingpb.NewMetricsServiceV2Client(),
}
.SetGoogleClientInfo()
return , nil
}
func ( *MetricsClient) () *grpc.ClientConn {
return .conn
}
func ( *MetricsClient) () error {
return .conn.Close()
}
func ( *MetricsClient) ( ...string) {
:= append([]string{"gl-go", versionGo()}, ...)
= append(, "gapic", versionClient, "gax", gax.Version, "grpc", grpc.Version)
.xGoogMetadata = metadata.Pairs("x-goog-api-client", gax.XGoogHeader(...))
}
func ( *MetricsClient) ( context.Context, *loggingpb.ListLogMetricsRequest, ...gax.CallOption) *LogMetricIterator {
:= metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(.GetParent())))
= insertMetadata(, .xGoogMetadata, )
= append(.CallOptions.ListLogMetrics[0:len(.CallOptions.ListLogMetrics):len(.CallOptions.ListLogMetrics)], ...)
:= &LogMetricIterator{}
= proto.Clone().(*loggingpb.ListLogMetricsRequest)
.InternalFetch = func( int, string) ([]*loggingpb.LogMetric, string, error) {
var *loggingpb.ListLogMetricsResponse
.PageToken =
if > math.MaxInt32 {
.PageSize = math.MaxInt32
} else {
.PageSize = int32()
}
:= gax.Invoke(, func( context.Context, gax.CallSettings) error {
var error
, = .metricsClient.ListLogMetrics(, , .GRPC...)
return
}, ...)
if != nil {
return nil, "",
}
return .Metrics, .NextPageToken, nil
}
:= func( int, string) (string, error) {
, , := .InternalFetch(, )
if != nil {
return "",
}
.items = append(.items, ...)
return , nil
}
.pageInfo, .nextFunc = iterator.NewPageInfo(, .bufLen, .takeBuf)
.pageInfo.MaxSize = int(.PageSize)
.pageInfo.Token = .PageToken
return
}
func ( *MetricsClient) ( context.Context, *loggingpb.GetLogMetricRequest, ...gax.CallOption) (*loggingpb.LogMetric, error) {
:= metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "metric_name", url.QueryEscape(.GetMetricName())))
= insertMetadata(, .xGoogMetadata, )
= append(.CallOptions.GetLogMetric[0:len(.CallOptions.GetLogMetric):len(.CallOptions.GetLogMetric)], ...)
var *loggingpb.LogMetric
:= gax.Invoke(, func( context.Context, gax.CallSettings) error {
var error
, = .metricsClient.GetLogMetric(, , .GRPC...)
return
}, ...)
if != nil {
return nil,
}
return , nil
}
func ( *MetricsClient) ( context.Context, *loggingpb.CreateLogMetricRequest, ...gax.CallOption) (*loggingpb.LogMetric, error) {
:= metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(.GetParent())))
= insertMetadata(, .xGoogMetadata, )
= append(.CallOptions.CreateLogMetric[0:len(.CallOptions.CreateLogMetric):len(.CallOptions.CreateLogMetric)], ...)
var *loggingpb.LogMetric
:= gax.Invoke(, func( context.Context, gax.CallSettings) error {
var error
, = .metricsClient.CreateLogMetric(, , .GRPC...)
return
}, ...)
if != nil {
return nil,
}
return , nil
}
func ( *MetricsClient) ( context.Context, *loggingpb.UpdateLogMetricRequest, ...gax.CallOption) (*loggingpb.LogMetric, error) {
:= metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "metric_name", url.QueryEscape(.GetMetricName())))
= insertMetadata(, .xGoogMetadata, )
= append(.CallOptions.UpdateLogMetric[0:len(.CallOptions.UpdateLogMetric):len(.CallOptions.UpdateLogMetric)], ...)
var *loggingpb.LogMetric
:= gax.Invoke(, func( context.Context, gax.CallSettings) error {
var error
, = .metricsClient.UpdateLogMetric(, , .GRPC...)
return
}, ...)
if != nil {
return nil,
}
return , nil
}
func ( *MetricsClient) ( context.Context, *loggingpb.DeleteLogMetricRequest, ...gax.CallOption) error {
:= metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "metric_name", url.QueryEscape(.GetMetricName())))
= insertMetadata(, .xGoogMetadata, )
= append(.CallOptions.DeleteLogMetric[0:len(.CallOptions.DeleteLogMetric):len(.CallOptions.DeleteLogMetric)], ...)
:= gax.Invoke(, func( context.Context, gax.CallSettings) error {
var error
_, = .metricsClient.DeleteLogMetric(, , .GRPC...)
return
}, ...)
return
}
func ( *LogMetricIterator) () *iterator.PageInfo {
return .pageInfo
}
func ( *LogMetricIterator) () (*loggingpb.LogMetric, error) {
var *loggingpb.LogMetric
if := .nextFunc(); != nil {
return ,
}
= .items[0]
.items = .items[1:]
return , nil
}
func ( *LogMetricIterator) () int {
return len(.items)
}
func ( *LogMetricIterator) () interface{} {
:= .items
.items = nil
return
![]() |
The pages are generated with Golds v0.3.2-preview. (GOOS=darwin GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |