Switch to using the dep tool and update all the dependencies

This commit is contained in:
Nick Craig-Wood
2017-05-11 15:39:54 +01:00
parent 5135ff73cb
commit 98c2d2c41b
5321 changed files with 4483197 additions and 5918 deletions
+11
View File
@@ -0,0 +1,11 @@
Auto-generated logging v2 clients
=================================
This package includes auto-generated clients for the logging v2 API.
Use the handwritten logging client (in the parent directory,
cloud.google.com/go/logging) in preference to this.
This code is EXPERIMENTAL and subject to CHANGE AT ANY TIME.
+315
View File
@@ -0,0 +1,315 @@
// Copyright 2017, Google Inc. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// AUTO-GENERATED CODE. DO NOT EDIT.
package logging
import (
"math"
"time"
"cloud.google.com/go/internal/version"
gax "github.com/googleapis/gax-go"
"golang.org/x/net/context"
"google.golang.org/api/iterator"
"google.golang.org/api/option"
"google.golang.org/api/transport"
loggingpb "google.golang.org/genproto/googleapis/logging/v2"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
)
var (
configProjectPathTemplate = gax.MustCompilePathTemplate("projects/{project}")
configSinkPathTemplate = gax.MustCompilePathTemplate("projects/{project}/sinks/{sink}")
)
// ConfigCallOptions contains the retry settings for each method of ConfigClient.
type ConfigCallOptions struct {
ListSinks []gax.CallOption
GetSink []gax.CallOption
CreateSink []gax.CallOption
UpdateSink []gax.CallOption
DeleteSink []gax.CallOption
}
func defaultConfigClientOptions() []option.ClientOption {
return []option.ClientOption{
option.WithEndpoint("logging.googleapis.com:443"),
option.WithScopes(
"https://www.googleapis.com/auth/cloud-platform",
"https://www.googleapis.com/auth/cloud-platform.read-only",
"https://www.googleapis.com/auth/logging.admin",
"https://www.googleapis.com/auth/logging.read",
"https://www.googleapis.com/auth/logging.write",
),
}
}
func defaultConfigCallOptions() *ConfigCallOptions {
retry := map[[2]string][]gax.CallOption{
{"default", "idempotent"}: {
gax.WithRetry(func() gax.Retryer {
return gax.OnCodes([]codes.Code{
codes.DeadlineExceeded,
codes.Unavailable,
}, gax.Backoff{
Initial: 100 * time.Millisecond,
Max: 1000 * time.Millisecond,
Multiplier: 1.2,
})
}),
},
{"default", "non_idempotent"}: {
gax.WithRetry(func() gax.Retryer {
return gax.OnCodes([]codes.Code{
codes.Unavailable,
}, gax.Backoff{
Initial: 100 * time.Millisecond,
Max: 1000 * time.Millisecond,
Multiplier: 1.2,
})
}),
},
}
return &ConfigCallOptions{
ListSinks: retry[[2]string{"default", "idempotent"}],
GetSink: retry[[2]string{"default", "idempotent"}],
CreateSink: retry[[2]string{"default", "non_idempotent"}],
UpdateSink: retry[[2]string{"default", "non_idempotent"}],
DeleteSink: retry[[2]string{"default", "idempotent"}],
}
}
// ConfigClient is a client for interacting with Stackdriver Logging API.
type ConfigClient struct {
// The connection to the service.
conn *grpc.ClientConn
// The gRPC API client.
configClient loggingpb.ConfigServiceV2Client
// The call options for this service.
CallOptions *ConfigCallOptions
// The metadata to be sent with each request.
xGoogHeader string
}
// NewConfigClient creates a new config service v2 client.
//
// Service for configuring sinks used to export log entries outside of
// Stackdriver Logging.
func NewConfigClient(ctx context.Context, opts ...option.ClientOption) (*ConfigClient, error) {
conn, err := transport.DialGRPC(ctx, append(defaultConfigClientOptions(), opts...)...)
if err != nil {
return nil, err
}
c := &ConfigClient{
conn: conn,
CallOptions: defaultConfigCallOptions(),
configClient: loggingpb.NewConfigServiceV2Client(conn),
}
c.SetGoogleClientInfo()
return c, nil
}
// Connection returns the client's connection to the API service.
func (c *ConfigClient) Connection() *grpc.ClientConn {
return c.conn
}
// Close closes the connection to the API service. The user should invoke this when
// the client is no longer required.
func (c *ConfigClient) Close() error {
return c.conn.Close()
}
// SetGoogleClientInfo sets the name and version of the application in
// the `x-goog-api-client` header passed on each request. Intended for
// use by Google-written clients.
func (c *ConfigClient) SetGoogleClientInfo(keyval ...string) {
kv := append([]string{"gl-go", version.Go()}, keyval...)
kv = append(kv, "gapic", version.Repo, "gax", gax.Version, "grpc", "")
c.xGoogHeader = gax.XGoogHeader(kv...)
}
// ConfigProjectPath returns the path for the project resource.
func ConfigProjectPath(project string) string {
path, err := configProjectPathTemplate.Render(map[string]string{
"project": project,
})
if err != nil {
panic(err)
}
return path
}
// ConfigSinkPath returns the path for the sink resource.
func ConfigSinkPath(project, sink string) string {
path, err := configSinkPathTemplate.Render(map[string]string{
"project": project,
"sink": sink,
})
if err != nil {
panic(err)
}
return path
}
// ListSinks lists sinks.
func (c *ConfigClient) ListSinks(ctx context.Context, req *loggingpb.ListSinksRequest) *LogSinkIterator {
ctx = insertXGoog(ctx, c.xGoogHeader)
it := &LogSinkIterator{}
it.InternalFetch = func(pageSize int, pageToken string) ([]*loggingpb.LogSink, string, error) {
var resp *loggingpb.ListSinksResponse
req.PageToken = pageToken
if pageSize > math.MaxInt32 {
req.PageSize = math.MaxInt32
} else {
req.PageSize = int32(pageSize)
}
err := gax.Invoke(ctx, func(ctx context.Context) error {
var err error
resp, err = c.configClient.ListSinks(ctx, req)
return err
}, c.CallOptions.ListSinks...)
if err != nil {
return nil, "", err
}
return resp.Sinks, resp.NextPageToken, nil
}
fetch := func(pageSize int, pageToken string) (string, error) {
items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
if err != nil {
return "", err
}
it.items = append(it.items, items...)
return nextPageToken, nil
}
it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
return it
}
// GetSink gets a sink.
func (c *ConfigClient) GetSink(ctx context.Context, req *loggingpb.GetSinkRequest) (*loggingpb.LogSink, error) {
ctx = insertXGoog(ctx, c.xGoogHeader)
var resp *loggingpb.LogSink
err := gax.Invoke(ctx, func(ctx context.Context) error {
var err error
resp, err = c.configClient.GetSink(ctx, req)
return err
}, c.CallOptions.GetSink...)
if err != nil {
return nil, err
}
return resp, nil
}
// CreateSink creates a sink that exports specified log entries to a destination. The
// export of newly-ingested log entries begins immediately, unless the current
// time is outside the sink's start and end times or the sink's
// `writer_identity` is not permitted to write to the destination. A sink can
// export log entries only from the resource owning the sink.
func (c *ConfigClient) CreateSink(ctx context.Context, req *loggingpb.CreateSinkRequest) (*loggingpb.LogSink, error) {
ctx = insertXGoog(ctx, c.xGoogHeader)
var resp *loggingpb.LogSink
err := gax.Invoke(ctx, func(ctx context.Context) error {
var err error
resp, err = c.configClient.CreateSink(ctx, req)
return err
}, c.CallOptions.CreateSink...)
if err != nil {
return nil, err
}
return resp, nil
}
// UpdateSink updates a sink. If the named sink doesn't exist, then this method is
// identical to
// [sinks.create](/logging/docs/api/reference/rest/v2/projects.sinks/create).
// If the named sink does exist, then this method replaces the following
// fields in the existing sink with values from the new sink: `destination`,
// `filter`, `output_version_format`, `start_time`, and `end_time`.
// The updated filter might also have a new `writer_identity`; see the
// `unique_writer_identity` field.
func (c *ConfigClient) UpdateSink(ctx context.Context, req *loggingpb.UpdateSinkRequest) (*loggingpb.LogSink, error) {
ctx = insertXGoog(ctx, c.xGoogHeader)
var resp *loggingpb.LogSink
err := gax.Invoke(ctx, func(ctx context.Context) error {
var err error
resp, err = c.configClient.UpdateSink(ctx, req)
return err
}, c.CallOptions.UpdateSink...)
if err != nil {
return nil, err
}
return resp, nil
}
// DeleteSink deletes a sink. If the sink has a unique `writer_identity`, then that
// service account is also deleted.
func (c *ConfigClient) DeleteSink(ctx context.Context, req *loggingpb.DeleteSinkRequest) error {
ctx = insertXGoog(ctx, c.xGoogHeader)
err := gax.Invoke(ctx, func(ctx context.Context) error {
var err error
_, err = c.configClient.DeleteSink(ctx, req)
return err
}, c.CallOptions.DeleteSink...)
return err
}
// LogSinkIterator manages a stream of *loggingpb.LogSink.
type LogSinkIterator struct {
items []*loggingpb.LogSink
pageInfo *iterator.PageInfo
nextFunc func() error
// InternalFetch is for use by the Google Cloud Libraries only.
// It is not part of the stable interface of this package.
//
// InternalFetch returns results from a single call to the underlying RPC.
// The number of results is no greater than pageSize.
// If there are no more results, nextPageToken is empty and err is nil.
InternalFetch func(pageSize int, pageToken string) (results []*loggingpb.LogSink, nextPageToken string, err error)
}
// PageInfo supports pagination. See the google.golang.org/api/iterator package for details.
func (it *LogSinkIterator) PageInfo() *iterator.PageInfo {
return it.pageInfo
}
// Next returns the next result. Its second return value is iterator.Done if there are no more
// results. Once Next returns Done, all subsequent calls will return Done.
func (it *LogSinkIterator) Next() (*loggingpb.LogSink, error) {
var item *loggingpb.LogSink
if err := it.nextFunc(); err != nil {
return item, err
}
item = it.items[0]
it.items = it.items[1:]
return item, nil
}
func (it *LogSinkIterator) bufLen() int {
return len(it.items)
}
func (it *LogSinkIterator) takeBuf() interface{} {
b := it.items
it.items = nil
return b
}
+125
View File
@@ -0,0 +1,125 @@
// Copyright 2017, Google Inc. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// AUTO-GENERATED CODE. DO NOT EDIT.
package logging_test
import (
"cloud.google.com/go/logging/apiv2"
"golang.org/x/net/context"
loggingpb "google.golang.org/genproto/googleapis/logging/v2"
)
func ExampleNewConfigClient() {
ctx := context.Background()
c, err := logging.NewConfigClient(ctx)
if err != nil {
// TODO: Handle error.
}
// TODO: Use client.
_ = c
}
func ExampleConfigClient_ListSinks() {
ctx := context.Background()
c, err := logging.NewConfigClient(ctx)
if err != nil {
// TODO: Handle error.
}
req := &loggingpb.ListSinksRequest{
// TODO: Fill request struct fields.
}
it := c.ListSinks(ctx, req)
for {
resp, err := it.Next()
if err != nil {
// TODO: Handle error.
break
}
// TODO: Use resp.
_ = resp
}
}
func ExampleConfigClient_GetSink() {
ctx := context.Background()
c, err := logging.NewConfigClient(ctx)
if err != nil {
// TODO: Handle error.
}
req := &loggingpb.GetSinkRequest{
// TODO: Fill request struct fields.
}
resp, err := c.GetSink(ctx, req)
if err != nil {
// TODO: Handle error.
}
// TODO: Use resp.
_ = resp
}
func ExampleConfigClient_CreateSink() {
ctx := context.Background()
c, err := logging.NewConfigClient(ctx)
if err != nil {
// TODO: Handle error.
}
req := &loggingpb.CreateSinkRequest{
// TODO: Fill request struct fields.
}
resp, err := c.CreateSink(ctx, req)
if err != nil {
// TODO: Handle error.
}
// TODO: Use resp.
_ = resp
}
func ExampleConfigClient_UpdateSink() {
ctx := context.Background()
c, err := logging.NewConfigClient(ctx)
if err != nil {
// TODO: Handle error.
}
req := &loggingpb.UpdateSinkRequest{
// TODO: Fill request struct fields.
}
resp, err := c.UpdateSink(ctx, req)
if err != nil {
// TODO: Handle error.
}
// TODO: Use resp.
_ = resp
}
func ExampleConfigClient_DeleteSink() {
ctx := context.Background()
c, err := logging.NewConfigClient(ctx)
if err != nil {
// TODO: Handle error.
}
req := &loggingpb.DeleteSinkRequest{
// TODO: Fill request struct fields.
}
err = c.DeleteSink(ctx, req)
if err != nil {
// TODO: Handle error.
}
}
+36
View File
@@ -0,0 +1,36 @@
// Copyright 2017, Google Inc. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// AUTO-GENERATED CODE. DO NOT EDIT.
// Package logging is an experimental, auto-generated package for the
// logging API.
//
// The Stackdriver Logging API lets you write log entries and manage your
// logs, log sinks and logs-based metrics.
//
// Use the client at cloud.google.com/go/logging in preference to this.
package logging // import "cloud.google.com/go/logging/apiv2"
import (
"golang.org/x/net/context"
"google.golang.org/grpc/metadata"
)
func insertXGoog(ctx context.Context, val string) context.Context {
md, _ := metadata.FromContext(ctx)
md = md.Copy()
md["x-goog-api-client"] = []string{val}
return metadata.NewContext(ctx, md)
}
+443
View File
@@ -0,0 +1,443 @@
// Copyright 2017, Google Inc. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// AUTO-GENERATED CODE. DO NOT EDIT.
package logging
import (
"math"
"time"
"cloud.google.com/go/internal/version"
gax "github.com/googleapis/gax-go"
"golang.org/x/net/context"
"google.golang.org/api/iterator"
"google.golang.org/api/option"
"google.golang.org/api/transport"
monitoredrespb "google.golang.org/genproto/googleapis/api/monitoredres"
loggingpb "google.golang.org/genproto/googleapis/logging/v2"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
)
var (
loggingProjectPathTemplate = gax.MustCompilePathTemplate("projects/{project}")
loggingLogPathTemplate = gax.MustCompilePathTemplate("projects/{project}/logs/{log}")
)
// CallOptions contains the retry settings for each method of Client.
type CallOptions struct {
DeleteLog []gax.CallOption
WriteLogEntries []gax.CallOption
ListLogEntries []gax.CallOption
ListMonitoredResourceDescriptors []gax.CallOption
ListLogs []gax.CallOption
}
func defaultClientOptions() []option.ClientOption {
return []option.ClientOption{
option.WithEndpoint("logging.googleapis.com:443"),
option.WithScopes(
"https://www.googleapis.com/auth/cloud-platform",
"https://www.googleapis.com/auth/cloud-platform.read-only",
"https://www.googleapis.com/auth/logging.admin",
"https://www.googleapis.com/auth/logging.read",
"https://www.googleapis.com/auth/logging.write",
),
}
}
func defaultCallOptions() *CallOptions {
retry := map[[2]string][]gax.CallOption{
{"default", "idempotent"}: {
gax.WithRetry(func() gax.Retryer {
return gax.OnCodes([]codes.Code{
codes.DeadlineExceeded,
codes.Unavailable,
}, gax.Backoff{
Initial: 100 * time.Millisecond,
Max: 1000 * time.Millisecond,
Multiplier: 1.2,
})
}),
},
{"default", "non_idempotent"}: {
gax.WithRetry(func() gax.Retryer {
return gax.OnCodes([]codes.Code{
codes.Unavailable,
}, gax.Backoff{
Initial: 100 * time.Millisecond,
Max: 1000 * time.Millisecond,
Multiplier: 1.2,
})
}),
},
{"list", "idempotent"}: {
gax.WithRetry(func() gax.Retryer {
return gax.OnCodes([]codes.Code{
codes.DeadlineExceeded,
codes.Unavailable,
}, gax.Backoff{
Initial: 100 * time.Millisecond,
Max: 1000 * time.Millisecond,
Multiplier: 1.2,
})
}),
},
}
return &CallOptions{
DeleteLog: retry[[2]string{"default", "idempotent"}],
WriteLogEntries: retry[[2]string{"default", "non_idempotent"}],
ListLogEntries: retry[[2]string{"list", "idempotent"}],
ListMonitoredResourceDescriptors: retry[[2]string{"default", "idempotent"}],
ListLogs: retry[[2]string{"default", "idempotent"}],
}
}
// Client is a client for interacting with Stackdriver Logging API.
type Client struct {
// The connection to the service.
conn *grpc.ClientConn
// The gRPC API client.
client loggingpb.LoggingServiceV2Client
// The call options for this service.
CallOptions *CallOptions
// The metadata to be sent with each request.
xGoogHeader string
}
// NewClient creates a new logging service v2 client.
//
// Service for ingesting and querying logs.
func NewClient(ctx context.Context, opts ...option.ClientOption) (*Client, error) {
conn, err := transport.DialGRPC(ctx, append(defaultClientOptions(), opts...)...)
if err != nil {
return nil, err
}
c := &Client{
conn: conn,
CallOptions: defaultCallOptions(),
client: loggingpb.NewLoggingServiceV2Client(conn),
}
c.SetGoogleClientInfo()
return c, nil
}
// Connection returns the client's connection to the API service.
func (c *Client) Connection() *grpc.ClientConn {
return c.conn
}
// Close closes the connection to the API service. The user should invoke this when
// the client is no longer required.
func (c *Client) Close() error {
return c.conn.Close()
}
// SetGoogleClientInfo sets the name and version of the application in
// the `x-goog-api-client` header passed on each request. Intended for
// use by Google-written clients.
func (c *Client) SetGoogleClientInfo(keyval ...string) {
kv := append([]string{"gl-go", version.Go()}, keyval...)
kv = append(kv, "gapic", version.Repo, "gax", gax.Version, "grpc", "")
c.xGoogHeader = gax.XGoogHeader(kv...)
}
// LoggingProjectPath returns the path for the project resource.
func LoggingProjectPath(project string) string {
path, err := loggingProjectPathTemplate.Render(map[string]string{
"project": project,
})
if err != nil {
panic(err)
}
return path
}
// LoggingLogPath returns the path for the log resource.
func LoggingLogPath(project, log string) string {
path, err := loggingLogPathTemplate.Render(map[string]string{
"project": project,
"log": log,
})
if err != nil {
panic(err)
}
return path
}
// DeleteLog deletes all the log entries in a log.
// The log reappears if it receives new entries.
func (c *Client) DeleteLog(ctx context.Context, req *loggingpb.DeleteLogRequest) error {
ctx = insertXGoog(ctx, c.xGoogHeader)
err := gax.Invoke(ctx, func(ctx context.Context) error {
var err error
_, err = c.client.DeleteLog(ctx, req)
return err
}, c.CallOptions.DeleteLog...)
return err
}
// WriteLogEntries writes log entries to Stackdriver Logging. All log entries are
// written by this method.
func (c *Client) WriteLogEntries(ctx context.Context, req *loggingpb.WriteLogEntriesRequest) (*loggingpb.WriteLogEntriesResponse, error) {
ctx = insertXGoog(ctx, c.xGoogHeader)
var resp *loggingpb.WriteLogEntriesResponse
err := gax.Invoke(ctx, func(ctx context.Context) error {
var err error
resp, err = c.client.WriteLogEntries(ctx, req)
return err
}, c.CallOptions.WriteLogEntries...)
if err != nil {
return nil, err
}
return resp, nil
}
// ListLogEntries lists log entries. Use this method to retrieve log entries from
// Stackdriver Logging. For ways to export log entries, see
// [Exporting Logs](/logging/docs/export).
func (c *Client) ListLogEntries(ctx context.Context, req *loggingpb.ListLogEntriesRequest) *LogEntryIterator {
ctx = insertXGoog(ctx, c.xGoogHeader)
it := &LogEntryIterator{}
it.InternalFetch = func(pageSize int, pageToken string) ([]*loggingpb.LogEntry, string, error) {
var resp *loggingpb.ListLogEntriesResponse
req.PageToken = pageToken
if pageSize > math.MaxInt32 {
req.PageSize = math.MaxInt32
} else {
req.PageSize = int32(pageSize)
}
err := gax.Invoke(ctx, func(ctx context.Context) error {
var err error
resp, err = c.client.ListLogEntries(ctx, req)
return err
}, c.CallOptions.ListLogEntries...)
if err != nil {
return nil, "", err
}
return resp.Entries, resp.NextPageToken, nil
}
fetch := func(pageSize int, pageToken string) (string, error) {
items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
if err != nil {
return "", err
}
it.items = append(it.items, items...)
return nextPageToken, nil
}
it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
return it
}
// ListMonitoredResourceDescriptors lists the descriptors for monitored resource types used by Stackdriver
// Logging.
func (c *Client) ListMonitoredResourceDescriptors(ctx context.Context, req *loggingpb.ListMonitoredResourceDescriptorsRequest) *MonitoredResourceDescriptorIterator {
ctx = insertXGoog(ctx, c.xGoogHeader)
it := &MonitoredResourceDescriptorIterator{}
it.InternalFetch = func(pageSize int, pageToken string) ([]*monitoredrespb.MonitoredResourceDescriptor, string, error) {
var resp *loggingpb.ListMonitoredResourceDescriptorsResponse
req.PageToken = pageToken
if pageSize > math.MaxInt32 {
req.PageSize = math.MaxInt32
} else {
req.PageSize = int32(pageSize)
}
err := gax.Invoke(ctx, func(ctx context.Context) error {
var err error
resp, err = c.client.ListMonitoredResourceDescriptors(ctx, req)
return err
}, c.CallOptions.ListMonitoredResourceDescriptors...)
if err != nil {
return nil, "", err
}
return resp.ResourceDescriptors, resp.NextPageToken, nil
}
fetch := func(pageSize int, pageToken string) (string, error) {
items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
if err != nil {
return "", err
}
it.items = append(it.items, items...)
return nextPageToken, nil
}
it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
return it
}
// ListLogs lists the logs in projects or organizations.
// Only logs that have entries are listed.
func (c *Client) ListLogs(ctx context.Context, req *loggingpb.ListLogsRequest) *StringIterator {
ctx = insertXGoog(ctx, c.xGoogHeader)
it := &StringIterator{}
it.InternalFetch = func(pageSize int, pageToken string) ([]string, string, error) {
var resp *loggingpb.ListLogsResponse
req.PageToken = pageToken
if pageSize > math.MaxInt32 {
req.PageSize = math.MaxInt32
} else {
req.PageSize = int32(pageSize)
}
err := gax.Invoke(ctx, func(ctx context.Context) error {
var err error
resp, err = c.client.ListLogs(ctx, req)
return err
}, c.CallOptions.ListLogs...)
if err != nil {
return nil, "", err
}
return resp.LogNames, resp.NextPageToken, nil
}
fetch := func(pageSize int, pageToken string) (string, error) {
items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
if err != nil {
return "", err
}
it.items = append(it.items, items...)
return nextPageToken, nil
}
it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
return it
}
// LogEntryIterator manages a stream of *loggingpb.LogEntry.
type LogEntryIterator struct {
items []*loggingpb.LogEntry
pageInfo *iterator.PageInfo
nextFunc func() error
// InternalFetch is for use by the Google Cloud Libraries only.
// It is not part of the stable interface of this package.
//
// InternalFetch returns results from a single call to the underlying RPC.
// The number of results is no greater than pageSize.
// If there are no more results, nextPageToken is empty and err is nil.
InternalFetch func(pageSize int, pageToken string) (results []*loggingpb.LogEntry, nextPageToken string, err error)
}
// PageInfo supports pagination. See the google.golang.org/api/iterator package for details.
func (it *LogEntryIterator) PageInfo() *iterator.PageInfo {
return it.pageInfo
}
// Next returns the next result. Its second return value is iterator.Done if there are no more
// results. Once Next returns Done, all subsequent calls will return Done.
func (it *LogEntryIterator) Next() (*loggingpb.LogEntry, error) {
var item *loggingpb.LogEntry
if err := it.nextFunc(); err != nil {
return item, err
}
item = it.items[0]
it.items = it.items[1:]
return item, nil
}
func (it *LogEntryIterator) bufLen() int {
return len(it.items)
}
func (it *LogEntryIterator) takeBuf() interface{} {
b := it.items
it.items = nil
return b
}
// MonitoredResourceDescriptorIterator manages a stream of *monitoredrespb.MonitoredResourceDescriptor.
type MonitoredResourceDescriptorIterator struct {
items []*monitoredrespb.MonitoredResourceDescriptor
pageInfo *iterator.PageInfo
nextFunc func() error
// InternalFetch is for use by the Google Cloud Libraries only.
// It is not part of the stable interface of this package.
//
// InternalFetch returns results from a single call to the underlying RPC.
// The number of results is no greater than pageSize.
// If there are no more results, nextPageToken is empty and err is nil.
InternalFetch func(pageSize int, pageToken string) (results []*monitoredrespb.MonitoredResourceDescriptor, nextPageToken string, err error)
}
// PageInfo supports pagination. See the google.golang.org/api/iterator package for details.
func (it *MonitoredResourceDescriptorIterator) PageInfo() *iterator.PageInfo {
return it.pageInfo
}
// Next returns the next result. Its second return value is iterator.Done if there are no more
// results. Once Next returns Done, all subsequent calls will return Done.
func (it *MonitoredResourceDescriptorIterator) Next() (*monitoredrespb.MonitoredResourceDescriptor, error) {
var item *monitoredrespb.MonitoredResourceDescriptor
if err := it.nextFunc(); err != nil {
return item, err
}
item = it.items[0]
it.items = it.items[1:]
return item, nil
}
func (it *MonitoredResourceDescriptorIterator) bufLen() int {
return len(it.items)
}
func (it *MonitoredResourceDescriptorIterator) takeBuf() interface{} {
b := it.items
it.items = nil
return b
}
// StringIterator manages a stream of string.
type StringIterator struct {
items []string
pageInfo *iterator.PageInfo
nextFunc func() error
// InternalFetch is for use by the Google Cloud Libraries only.
// It is not part of the stable interface of this package.
//
// InternalFetch returns results from a single call to the underlying RPC.
// The number of results is no greater than pageSize.
// If there are no more results, nextPageToken is empty and err is nil.
InternalFetch func(pageSize int, pageToken string) (results []string, nextPageToken string, err error)
}
// PageInfo supports pagination. See the google.golang.org/api/iterator package for details.
func (it *StringIterator) PageInfo() *iterator.PageInfo {
return it.pageInfo
}
// Next returns the next result. Its second return value is iterator.Done if there are no more
// results. Once Next returns Done, all subsequent calls will return Done.
func (it *StringIterator) Next() (string, error) {
var item string
if err := it.nextFunc(); err != nil {
return item, err
}
item = it.items[0]
it.items = it.items[1:]
return item, nil
}
func (it *StringIterator) bufLen() int {
return len(it.items)
}
func (it *StringIterator) takeBuf() interface{} {
b := it.items
it.items = nil
return b
}
+133
View File
@@ -0,0 +1,133 @@
// Copyright 2017, Google Inc. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// AUTO-GENERATED CODE. DO NOT EDIT.
package logging_test
import (
"cloud.google.com/go/logging/apiv2"
"golang.org/x/net/context"
loggingpb "google.golang.org/genproto/googleapis/logging/v2"
)
func ExampleNewClient() {
ctx := context.Background()
c, err := logging.NewClient(ctx)
if err != nil {
// TODO: Handle error.
}
// TODO: Use client.
_ = c
}
func ExampleClient_DeleteLog() {
ctx := context.Background()
c, err := logging.NewClient(ctx)
if err != nil {
// TODO: Handle error.
}
req := &loggingpb.DeleteLogRequest{
// TODO: Fill request struct fields.
}
err = c.DeleteLog(ctx, req)
if err != nil {
// TODO: Handle error.
}
}
func ExampleClient_WriteLogEntries() {
ctx := context.Background()
c, err := logging.NewClient(ctx)
if err != nil {
// TODO: Handle error.
}
req := &loggingpb.WriteLogEntriesRequest{
// TODO: Fill request struct fields.
}
resp, err := c.WriteLogEntries(ctx, req)
if err != nil {
// TODO: Handle error.
}
// TODO: Use resp.
_ = resp
}
func ExampleClient_ListLogEntries() {
ctx := context.Background()
c, err := logging.NewClient(ctx)
if err != nil {
// TODO: Handle error.
}
req := &loggingpb.ListLogEntriesRequest{
// TODO: Fill request struct fields.
}
it := c.ListLogEntries(ctx, req)
for {
resp, err := it.Next()
if err != nil {
// TODO: Handle error.
break
}
// TODO: Use resp.
_ = resp
}
}
func ExampleClient_ListMonitoredResourceDescriptors() {
ctx := context.Background()
c, err := logging.NewClient(ctx)
if err != nil {
// TODO: Handle error.
}
req := &loggingpb.ListMonitoredResourceDescriptorsRequest{
// TODO: Fill request struct fields.
}
it := c.ListMonitoredResourceDescriptors(ctx, req)
for {
resp, err := it.Next()
if err != nil {
// TODO: Handle error.
break
}
// TODO: Use resp.
_ = resp
}
}
func ExampleClient_ListLogs() {
ctx := context.Background()
c, err := logging.NewClient(ctx)
if err != nil {
// TODO: Handle error.
}
req := &loggingpb.ListLogsRequest{
// TODO: Fill request struct fields.
}
it := c.ListLogs(ctx, req)
for {
resp, err := it.Next()
if err != nil {
// TODO: Handle error.
break
}
// TODO: Use resp.
_ = resp
}
}
+302
View File
@@ -0,0 +1,302 @@
// Copyright 2017, Google Inc. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// AUTO-GENERATED CODE. DO NOT EDIT.
package logging
import (
"math"
"time"
"cloud.google.com/go/internal/version"
gax "github.com/googleapis/gax-go"
"golang.org/x/net/context"
"google.golang.org/api/iterator"
"google.golang.org/api/option"
"google.golang.org/api/transport"
loggingpb "google.golang.org/genproto/googleapis/logging/v2"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
)
var (
metricsProjectPathTemplate = gax.MustCompilePathTemplate("projects/{project}")
metricsMetricPathTemplate = gax.MustCompilePathTemplate("projects/{project}/metrics/{metric}")
)
// MetricsCallOptions contains the retry settings for each method of MetricsClient.
type MetricsCallOptions struct {
ListLogMetrics []gax.CallOption
GetLogMetric []gax.CallOption
CreateLogMetric []gax.CallOption
UpdateLogMetric []gax.CallOption
DeleteLogMetric []gax.CallOption
}
func defaultMetricsClientOptions() []option.ClientOption {
return []option.ClientOption{
option.WithEndpoint("logging.googleapis.com:443"),
option.WithScopes(
"https://www.googleapis.com/auth/cloud-platform",
"https://www.googleapis.com/auth/cloud-platform.read-only",
"https://www.googleapis.com/auth/logging.admin",
"https://www.googleapis.com/auth/logging.read",
"https://www.googleapis.com/auth/logging.write",
),
}
}
func defaultMetricsCallOptions() *MetricsCallOptions {
retry := map[[2]string][]gax.CallOption{
{"default", "idempotent"}: {
gax.WithRetry(func() gax.Retryer {
return gax.OnCodes([]codes.Code{
codes.DeadlineExceeded,
codes.Unavailable,
}, gax.Backoff{
Initial: 100 * time.Millisecond,
Max: 1000 * time.Millisecond,
Multiplier: 1.2,
})
}),
},
{"default", "non_idempotent"}: {
gax.WithRetry(func() gax.Retryer {
return gax.OnCodes([]codes.Code{
codes.Unavailable,
}, gax.Backoff{
Initial: 100 * time.Millisecond,
Max: 1000 * time.Millisecond,
Multiplier: 1.2,
})
}),
},
}
return &MetricsCallOptions{
ListLogMetrics: retry[[2]string{"default", "idempotent"}],
GetLogMetric: retry[[2]string{"default", "idempotent"}],
CreateLogMetric: retry[[2]string{"default", "non_idempotent"}],
UpdateLogMetric: retry[[2]string{"default", "non_idempotent"}],
DeleteLogMetric: retry[[2]string{"default", "idempotent"}],
}
}
// MetricsClient is a client for interacting with Stackdriver Logging API.
type MetricsClient struct {
// The connection to the service.
conn *grpc.ClientConn
// The gRPC API client.
metricsClient loggingpb.MetricsServiceV2Client
// The call options for this service.
CallOptions *MetricsCallOptions
// The metadata to be sent with each request.
xGoogHeader string
}
// NewMetricsClient creates a new metrics service v2 client.
//
// Service for configuring logs-based metrics.
func NewMetricsClient(ctx context.Context, opts ...option.ClientOption) (*MetricsClient, error) {
conn, err := transport.DialGRPC(ctx, append(defaultMetricsClientOptions(), opts...)...)
if err != nil {
return nil, err
}
c := &MetricsClient{
conn: conn,
CallOptions: defaultMetricsCallOptions(),
metricsClient: loggingpb.NewMetricsServiceV2Client(conn),
}
c.SetGoogleClientInfo()
return c, nil
}
// Connection returns the client's connection to the API service.
func (c *MetricsClient) Connection() *grpc.ClientConn {
return c.conn
}
// Close closes the connection to the API service. The user should invoke this when
// the client is no longer required.
func (c *MetricsClient) Close() error {
return c.conn.Close()
}
// SetGoogleClientInfo sets the name and version of the application in
// the `x-goog-api-client` header passed on each request. Intended for
// use by Google-written clients.
func (c *MetricsClient) SetGoogleClientInfo(keyval ...string) {
kv := append([]string{"gl-go", version.Go()}, keyval...)
kv = append(kv, "gapic", version.Repo, "gax", gax.Version, "grpc", "")
c.xGoogHeader = gax.XGoogHeader(kv...)
}
// MetricsProjectPath returns the path for the project resource.
func MetricsProjectPath(project string) string {
path, err := metricsProjectPathTemplate.Render(map[string]string{
"project": project,
})
if err != nil {
panic(err)
}
return path
}
// MetricsMetricPath returns the path for the metric resource.
func MetricsMetricPath(project, metric string) string {
path, err := metricsMetricPathTemplate.Render(map[string]string{
"project": project,
"metric": metric,
})
if err != nil {
panic(err)
}
return path
}
// ListLogMetrics lists logs-based metrics.
func (c *MetricsClient) ListLogMetrics(ctx context.Context, req *loggingpb.ListLogMetricsRequest) *LogMetricIterator {
ctx = insertXGoog(ctx, c.xGoogHeader)
it := &LogMetricIterator{}
it.InternalFetch = func(pageSize int, pageToken string) ([]*loggingpb.LogMetric, string, error) {
var resp *loggingpb.ListLogMetricsResponse
req.PageToken = pageToken
if pageSize > math.MaxInt32 {
req.PageSize = math.MaxInt32
} else {
req.PageSize = int32(pageSize)
}
err := gax.Invoke(ctx, func(ctx context.Context) error {
var err error
resp, err = c.metricsClient.ListLogMetrics(ctx, req)
return err
}, c.CallOptions.ListLogMetrics...)
if err != nil {
return nil, "", err
}
return resp.Metrics, resp.NextPageToken, nil
}
fetch := func(pageSize int, pageToken string) (string, error) {
items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
if err != nil {
return "", err
}
it.items = append(it.items, items...)
return nextPageToken, nil
}
it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
return it
}
// GetLogMetric gets a logs-based metric.
func (c *MetricsClient) GetLogMetric(ctx context.Context, req *loggingpb.GetLogMetricRequest) (*loggingpb.LogMetric, error) {
ctx = insertXGoog(ctx, c.xGoogHeader)
var resp *loggingpb.LogMetric
err := gax.Invoke(ctx, func(ctx context.Context) error {
var err error
resp, err = c.metricsClient.GetLogMetric(ctx, req)
return err
}, c.CallOptions.GetLogMetric...)
if err != nil {
return nil, err
}
return resp, nil
}
// CreateLogMetric creates a logs-based metric.
func (c *MetricsClient) CreateLogMetric(ctx context.Context, req *loggingpb.CreateLogMetricRequest) (*loggingpb.LogMetric, error) {
ctx = insertXGoog(ctx, c.xGoogHeader)
var resp *loggingpb.LogMetric
err := gax.Invoke(ctx, func(ctx context.Context) error {
var err error
resp, err = c.metricsClient.CreateLogMetric(ctx, req)
return err
}, c.CallOptions.CreateLogMetric...)
if err != nil {
return nil, err
}
return resp, nil
}
// UpdateLogMetric creates or updates a logs-based metric.
func (c *MetricsClient) UpdateLogMetric(ctx context.Context, req *loggingpb.UpdateLogMetricRequest) (*loggingpb.LogMetric, error) {
ctx = insertXGoog(ctx, c.xGoogHeader)
var resp *loggingpb.LogMetric
err := gax.Invoke(ctx, func(ctx context.Context) error {
var err error
resp, err = c.metricsClient.UpdateLogMetric(ctx, req)
return err
}, c.CallOptions.UpdateLogMetric...)
if err != nil {
return nil, err
}
return resp, nil
}
// DeleteLogMetric deletes a logs-based metric.
func (c *MetricsClient) DeleteLogMetric(ctx context.Context, req *loggingpb.DeleteLogMetricRequest) error {
ctx = insertXGoog(ctx, c.xGoogHeader)
err := gax.Invoke(ctx, func(ctx context.Context) error {
var err error
_, err = c.metricsClient.DeleteLogMetric(ctx, req)
return err
}, c.CallOptions.DeleteLogMetric...)
return err
}
// LogMetricIterator manages a stream of *loggingpb.LogMetric.
type LogMetricIterator struct {
items []*loggingpb.LogMetric
pageInfo *iterator.PageInfo
nextFunc func() error
// InternalFetch is for use by the Google Cloud Libraries only.
// It is not part of the stable interface of this package.
//
// InternalFetch returns results from a single call to the underlying RPC.
// The number of results is no greater than pageSize.
// If there are no more results, nextPageToken is empty and err is nil.
InternalFetch func(pageSize int, pageToken string) (results []*loggingpb.LogMetric, nextPageToken string, err error)
}
// PageInfo supports pagination. See the google.golang.org/api/iterator package for details.
func (it *LogMetricIterator) PageInfo() *iterator.PageInfo {
return it.pageInfo
}
// Next returns the next result. Its second return value is iterator.Done if there are no more
// results. Once Next returns Done, all subsequent calls will return Done.
func (it *LogMetricIterator) Next() (*loggingpb.LogMetric, error) {
var item *loggingpb.LogMetric
if err := it.nextFunc(); err != nil {
return item, err
}
item = it.items[0]
it.items = it.items[1:]
return item, nil
}
func (it *LogMetricIterator) bufLen() int {
return len(it.items)
}
func (it *LogMetricIterator) takeBuf() interface{} {
b := it.items
it.items = nil
return b
}
+125
View File
@@ -0,0 +1,125 @@
// Copyright 2017, Google Inc. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// AUTO-GENERATED CODE. DO NOT EDIT.
package logging_test
import (
"cloud.google.com/go/logging/apiv2"
"golang.org/x/net/context"
loggingpb "google.golang.org/genproto/googleapis/logging/v2"
)
func ExampleNewMetricsClient() {
ctx := context.Background()
c, err := logging.NewMetricsClient(ctx)
if err != nil {
// TODO: Handle error.
}
// TODO: Use client.
_ = c
}
func ExampleMetricsClient_ListLogMetrics() {
ctx := context.Background()
c, err := logging.NewMetricsClient(ctx)
if err != nil {
// TODO: Handle error.
}
req := &loggingpb.ListLogMetricsRequest{
// TODO: Fill request struct fields.
}
it := c.ListLogMetrics(ctx, req)
for {
resp, err := it.Next()
if err != nil {
// TODO: Handle error.
break
}
// TODO: Use resp.
_ = resp
}
}
func ExampleMetricsClient_GetLogMetric() {
ctx := context.Background()
c, err := logging.NewMetricsClient(ctx)
if err != nil {
// TODO: Handle error.
}
req := &loggingpb.GetLogMetricRequest{
// TODO: Fill request struct fields.
}
resp, err := c.GetLogMetric(ctx, req)
if err != nil {
// TODO: Handle error.
}
// TODO: Use resp.
_ = resp
}
func ExampleMetricsClient_CreateLogMetric() {
ctx := context.Background()
c, err := logging.NewMetricsClient(ctx)
if err != nil {
// TODO: Handle error.
}
req := &loggingpb.CreateLogMetricRequest{
// TODO: Fill request struct fields.
}
resp, err := c.CreateLogMetric(ctx, req)
if err != nil {
// TODO: Handle error.
}
// TODO: Use resp.
_ = resp
}
func ExampleMetricsClient_UpdateLogMetric() {
ctx := context.Background()
c, err := logging.NewMetricsClient(ctx)
if err != nil {
// TODO: Handle error.
}
req := &loggingpb.UpdateLogMetricRequest{
// TODO: Fill request struct fields.
}
resp, err := c.UpdateLogMetric(ctx, req)
if err != nil {
// TODO: Handle error.
}
// TODO: Use resp.
_ = resp
}
func ExampleMetricsClient_DeleteLogMetric() {
ctx := context.Background()
c, err := logging.NewMetricsClient(ctx)
if err != nil {
// TODO: Handle error.
}
req := &loggingpb.DeleteLogMetricRequest{
// TODO: Fill request struct fields.
}
err = c.DeleteLogMetric(ctx, req)
if err != nil {
// TODO: Handle error.
}
}
File diff suppressed because it is too large Load Diff