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 logging 18 19import ( 20 "context" 21 "fmt" 22 "math" 23 "net/url" 24 "time" 25 26 "github.com/golang/protobuf/proto" 27 gax "github.com/googleapis/gax-go/v2" 28 "google.golang.org/api/iterator" 29 "google.golang.org/api/option" 30 gtransport "google.golang.org/api/transport/grpc" 31 loggingpb "google.golang.org/genproto/googleapis/logging/v2" 32 "google.golang.org/grpc" 33 "google.golang.org/grpc/codes" 34 "google.golang.org/grpc/metadata" 35) 36 37// ConfigCallOptions contains the retry settings for each method of ConfigClient. 38type ConfigCallOptions struct { 39 ListSinks []gax.CallOption 40 GetSink []gax.CallOption 41 CreateSink []gax.CallOption 42 UpdateSink []gax.CallOption 43 DeleteSink []gax.CallOption 44 ListExclusions []gax.CallOption 45 GetExclusion []gax.CallOption 46 CreateExclusion []gax.CallOption 47 UpdateExclusion []gax.CallOption 48 DeleteExclusion []gax.CallOption 49 GetCmekSettings []gax.CallOption 50 UpdateCmekSettings []gax.CallOption 51} 52 53func defaultConfigClientOptions() []option.ClientOption { 54 return []option.ClientOption{ 55 option.WithEndpoint("logging.googleapis.com:443"), 56 option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), 57 option.WithScopes(DefaultAuthScopes()...), 58 option.WithGRPCDialOption(grpc.WithDefaultCallOptions( 59 grpc.MaxCallRecvMsgSize(math.MaxInt32))), 60 } 61} 62 63func defaultConfigCallOptions() *ConfigCallOptions { 64 return &ConfigCallOptions{ 65 ListSinks: []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 GetSink: []gax.CallOption{ 78 gax.WithRetry(func() gax.Retryer { 79 return gax.OnCodes([]codes.Code{ 80 codes.Unavailable, 81 codes.DeadlineExceeded, 82 }, gax.Backoff{ 83 Initial: 100 * time.Millisecond, 84 Max: 60000 * time.Millisecond, 85 Multiplier: 1.30, 86 }) 87 }), 88 }, 89 CreateSink: []gax.CallOption{}, 90 UpdateSink: []gax.CallOption{ 91 gax.WithRetry(func() gax.Retryer { 92 return gax.OnCodes([]codes.Code{ 93 codes.Unavailable, 94 codes.DeadlineExceeded, 95 }, gax.Backoff{ 96 Initial: 100 * time.Millisecond, 97 Max: 60000 * time.Millisecond, 98 Multiplier: 1.30, 99 }) 100 }), 101 }, 102 DeleteSink: []gax.CallOption{ 103 gax.WithRetry(func() gax.Retryer { 104 return gax.OnCodes([]codes.Code{ 105 codes.Unavailable, 106 codes.DeadlineExceeded, 107 }, gax.Backoff{ 108 Initial: 100 * time.Millisecond, 109 Max: 60000 * time.Millisecond, 110 Multiplier: 1.30, 111 }) 112 }), 113 }, 114 ListExclusions: []gax.CallOption{ 115 gax.WithRetry(func() gax.Retryer { 116 return gax.OnCodes([]codes.Code{ 117 codes.Unavailable, 118 codes.DeadlineExceeded, 119 }, gax.Backoff{ 120 Initial: 100 * time.Millisecond, 121 Max: 60000 * time.Millisecond, 122 Multiplier: 1.30, 123 }) 124 }), 125 }, 126 GetExclusion: []gax.CallOption{ 127 gax.WithRetry(func() gax.Retryer { 128 return gax.OnCodes([]codes.Code{ 129 codes.Unavailable, 130 codes.DeadlineExceeded, 131 }, gax.Backoff{ 132 Initial: 100 * time.Millisecond, 133 Max: 60000 * time.Millisecond, 134 Multiplier: 1.30, 135 }) 136 }), 137 }, 138 CreateExclusion: []gax.CallOption{}, 139 UpdateExclusion: []gax.CallOption{}, 140 DeleteExclusion: []gax.CallOption{ 141 gax.WithRetry(func() gax.Retryer { 142 return gax.OnCodes([]codes.Code{ 143 codes.Unavailable, 144 codes.DeadlineExceeded, 145 }, gax.Backoff{ 146 Initial: 100 * time.Millisecond, 147 Max: 60000 * time.Millisecond, 148 Multiplier: 1.30, 149 }) 150 }), 151 }, 152 GetCmekSettings: []gax.CallOption{}, 153 UpdateCmekSettings: []gax.CallOption{}, 154 } 155} 156 157// ConfigClient is a client for interacting with Stackdriver Logging API. 158// 159// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. 160type ConfigClient struct { 161 // Connection pool of gRPC connections to the service. 162 connPool gtransport.ConnPool 163 164 // The gRPC API client. 165 configClient loggingpb.ConfigServiceV2Client 166 167 // The call options for this service. 168 CallOptions *ConfigCallOptions 169 170 // The x-goog-* metadata to be sent with each request. 171 xGoogMetadata metadata.MD 172} 173 174// NewConfigClient creates a new config service v2 client. 175// 176// Service for configuring sinks used to route log entries. 177func NewConfigClient(ctx context.Context, opts ...option.ClientOption) (*ConfigClient, error) { 178 connPool, err := gtransport.DialPool(ctx, append(defaultConfigClientOptions(), opts...)...) 179 if err != nil { 180 return nil, err 181 } 182 c := &ConfigClient{ 183 connPool: connPool, 184 CallOptions: defaultConfigCallOptions(), 185 186 configClient: loggingpb.NewConfigServiceV2Client(connPool), 187 } 188 c.SetGoogleClientInfo() 189 190 return c, nil 191} 192 193// Connection returns a connection to the API service. 194// 195// Deprecated. 196func (c *ConfigClient) Connection() *grpc.ClientConn { 197 return c.connPool.Conn() 198} 199 200// Close closes the connection to the API service. The user should invoke this when 201// the client is no longer required. 202func (c *ConfigClient) Close() error { 203 return c.connPool.Close() 204} 205 206// SetGoogleClientInfo sets the name and version of the application in 207// the `x-goog-api-client` header passed on each request. Intended for 208// use by Google-written clients. 209func (c *ConfigClient) SetGoogleClientInfo(keyval ...string) { 210 kv := append([]string{"gl-go", versionGo()}, keyval...) 211 kv = append(kv, "gapic", versionClient, "gax", gax.Version, "grpc", grpc.Version) 212 c.xGoogMetadata = metadata.Pairs("x-goog-api-client", gax.XGoogHeader(kv...)) 213} 214 215// ListSinks lists sinks. 216func (c *ConfigClient) ListSinks(ctx context.Context, req *loggingpb.ListSinksRequest, opts ...gax.CallOption) *LogSinkIterator { 217 md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))) 218 ctx = insertMetadata(ctx, c.xGoogMetadata, md) 219 opts = append(c.CallOptions.ListSinks[0:len(c.CallOptions.ListSinks):len(c.CallOptions.ListSinks)], opts...) 220 it := &LogSinkIterator{} 221 req = proto.Clone(req).(*loggingpb.ListSinksRequest) 222 it.InternalFetch = func(pageSize int, pageToken string) ([]*loggingpb.LogSink, string, error) { 223 var resp *loggingpb.ListSinksResponse 224 req.PageToken = pageToken 225 if pageSize > math.MaxInt32 { 226 req.PageSize = math.MaxInt32 227 } else { 228 req.PageSize = int32(pageSize) 229 } 230 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 231 var err error 232 resp, err = c.configClient.ListSinks(ctx, req, settings.GRPC...) 233 return err 234 }, opts...) 235 if err != nil { 236 return nil, "", err 237 } 238 239 it.Response = resp 240 return resp.Sinks, resp.NextPageToken, nil 241 } 242 fetch := func(pageSize int, pageToken string) (string, error) { 243 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) 244 if err != nil { 245 return "", err 246 } 247 it.items = append(it.items, items...) 248 return nextPageToken, nil 249 } 250 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) 251 it.pageInfo.MaxSize = int(req.PageSize) 252 it.pageInfo.Token = req.PageToken 253 return it 254} 255 256// GetSink gets a sink. 257func (c *ConfigClient) GetSink(ctx context.Context, req *loggingpb.GetSinkRequest, opts ...gax.CallOption) (*loggingpb.LogSink, error) { 258 md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "sink_name", url.QueryEscape(req.GetSinkName()))) 259 ctx = insertMetadata(ctx, c.xGoogMetadata, md) 260 opts = append(c.CallOptions.GetSink[0:len(c.CallOptions.GetSink):len(c.CallOptions.GetSink)], opts...) 261 var resp *loggingpb.LogSink 262 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 263 var err error 264 resp, err = c.configClient.GetSink(ctx, req, settings.GRPC...) 265 return err 266 }, opts...) 267 if err != nil { 268 return nil, err 269 } 270 return resp, nil 271} 272 273// CreateSink creates a sink that exports specified log entries to a destination. The 274// export of newly-ingested log entries begins immediately, unless the sink’s 275// writer_identity is not permitted to write to the destination. A sink can 276// export log entries only from the resource owning the sink. 277func (c *ConfigClient) CreateSink(ctx context.Context, req *loggingpb.CreateSinkRequest, opts ...gax.CallOption) (*loggingpb.LogSink, error) { 278 md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))) 279 ctx = insertMetadata(ctx, c.xGoogMetadata, md) 280 opts = append(c.CallOptions.CreateSink[0:len(c.CallOptions.CreateSink):len(c.CallOptions.CreateSink)], opts...) 281 var resp *loggingpb.LogSink 282 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 283 var err error 284 resp, err = c.configClient.CreateSink(ctx, req, settings.GRPC...) 285 return err 286 }, opts...) 287 if err != nil { 288 return nil, err 289 } 290 return resp, nil 291} 292 293// UpdateSink updates a sink. This method replaces the following fields in the existing 294// sink with values from the new sink: destination, and filter. 295// 296// The updated sink might also have a new writer_identity; see the 297// unique_writer_identity field. 298func (c *ConfigClient) UpdateSink(ctx context.Context, req *loggingpb.UpdateSinkRequest, opts ...gax.CallOption) (*loggingpb.LogSink, error) { 299 md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "sink_name", url.QueryEscape(req.GetSinkName()))) 300 ctx = insertMetadata(ctx, c.xGoogMetadata, md) 301 opts = append(c.CallOptions.UpdateSink[0:len(c.CallOptions.UpdateSink):len(c.CallOptions.UpdateSink)], opts...) 302 var resp *loggingpb.LogSink 303 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 304 var err error 305 resp, err = c.configClient.UpdateSink(ctx, req, settings.GRPC...) 306 return err 307 }, opts...) 308 if err != nil { 309 return nil, err 310 } 311 return resp, nil 312} 313 314// DeleteSink deletes a sink. If the sink has a unique writer_identity, then that 315// service account is also deleted. 316func (c *ConfigClient) DeleteSink(ctx context.Context, req *loggingpb.DeleteSinkRequest, opts ...gax.CallOption) error { 317 md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "sink_name", url.QueryEscape(req.GetSinkName()))) 318 ctx = insertMetadata(ctx, c.xGoogMetadata, md) 319 opts = append(c.CallOptions.DeleteSink[0:len(c.CallOptions.DeleteSink):len(c.CallOptions.DeleteSink)], opts...) 320 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 321 var err error 322 _, err = c.configClient.DeleteSink(ctx, req, settings.GRPC...) 323 return err 324 }, opts...) 325 return err 326} 327 328// ListExclusions lists all the exclusions in a parent resource. 329func (c *ConfigClient) ListExclusions(ctx context.Context, req *loggingpb.ListExclusionsRequest, opts ...gax.CallOption) *LogExclusionIterator { 330 md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))) 331 ctx = insertMetadata(ctx, c.xGoogMetadata, md) 332 opts = append(c.CallOptions.ListExclusions[0:len(c.CallOptions.ListExclusions):len(c.CallOptions.ListExclusions)], opts...) 333 it := &LogExclusionIterator{} 334 req = proto.Clone(req).(*loggingpb.ListExclusionsRequest) 335 it.InternalFetch = func(pageSize int, pageToken string) ([]*loggingpb.LogExclusion, string, error) { 336 var resp *loggingpb.ListExclusionsResponse 337 req.PageToken = pageToken 338 if pageSize > math.MaxInt32 { 339 req.PageSize = math.MaxInt32 340 } else { 341 req.PageSize = int32(pageSize) 342 } 343 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 344 var err error 345 resp, err = c.configClient.ListExclusions(ctx, req, settings.GRPC...) 346 return err 347 }, opts...) 348 if err != nil { 349 return nil, "", err 350 } 351 352 it.Response = resp 353 return resp.Exclusions, resp.NextPageToken, nil 354 } 355 fetch := func(pageSize int, pageToken string) (string, error) { 356 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) 357 if err != nil { 358 return "", err 359 } 360 it.items = append(it.items, items...) 361 return nextPageToken, nil 362 } 363 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) 364 it.pageInfo.MaxSize = int(req.PageSize) 365 it.pageInfo.Token = req.PageToken 366 return it 367} 368 369// GetExclusion gets the description of an exclusion. 370func (c *ConfigClient) GetExclusion(ctx context.Context, req *loggingpb.GetExclusionRequest, opts ...gax.CallOption) (*loggingpb.LogExclusion, error) { 371 md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) 372 ctx = insertMetadata(ctx, c.xGoogMetadata, md) 373 opts = append(c.CallOptions.GetExclusion[0:len(c.CallOptions.GetExclusion):len(c.CallOptions.GetExclusion)], opts...) 374 var resp *loggingpb.LogExclusion 375 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 376 var err error 377 resp, err = c.configClient.GetExclusion(ctx, req, settings.GRPC...) 378 return err 379 }, opts...) 380 if err != nil { 381 return nil, err 382 } 383 return resp, nil 384} 385 386// CreateExclusion creates a new exclusion in a specified parent resource. 387// Only log entries belonging to that resource can be excluded. 388// You can have up to 10 exclusions in a resource. 389func (c *ConfigClient) CreateExclusion(ctx context.Context, req *loggingpb.CreateExclusionRequest, opts ...gax.CallOption) (*loggingpb.LogExclusion, error) { 390 md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))) 391 ctx = insertMetadata(ctx, c.xGoogMetadata, md) 392 opts = append(c.CallOptions.CreateExclusion[0:len(c.CallOptions.CreateExclusion):len(c.CallOptions.CreateExclusion)], opts...) 393 var resp *loggingpb.LogExclusion 394 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 395 var err error 396 resp, err = c.configClient.CreateExclusion(ctx, req, settings.GRPC...) 397 return err 398 }, opts...) 399 if err != nil { 400 return nil, err 401 } 402 return resp, nil 403} 404 405// UpdateExclusion changes one or more properties of an existing exclusion. 406func (c *ConfigClient) UpdateExclusion(ctx context.Context, req *loggingpb.UpdateExclusionRequest, opts ...gax.CallOption) (*loggingpb.LogExclusion, error) { 407 md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) 408 ctx = insertMetadata(ctx, c.xGoogMetadata, md) 409 opts = append(c.CallOptions.UpdateExclusion[0:len(c.CallOptions.UpdateExclusion):len(c.CallOptions.UpdateExclusion)], opts...) 410 var resp *loggingpb.LogExclusion 411 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 412 var err error 413 resp, err = c.configClient.UpdateExclusion(ctx, req, settings.GRPC...) 414 return err 415 }, opts...) 416 if err != nil { 417 return nil, err 418 } 419 return resp, nil 420} 421 422// DeleteExclusion deletes an exclusion. 423func (c *ConfigClient) DeleteExclusion(ctx context.Context, req *loggingpb.DeleteExclusionRequest, opts ...gax.CallOption) error { 424 md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) 425 ctx = insertMetadata(ctx, c.xGoogMetadata, md) 426 opts = append(c.CallOptions.DeleteExclusion[0:len(c.CallOptions.DeleteExclusion):len(c.CallOptions.DeleteExclusion)], opts...) 427 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 428 var err error 429 _, err = c.configClient.DeleteExclusion(ctx, req, settings.GRPC...) 430 return err 431 }, opts...) 432 return err 433} 434 435// GetCmekSettings gets the Logs Router CMEK settings for the given resource. 436// 437// Note: CMEK for the Logs Router can currently only be configured for GCP 438// organizations. Once configured, it applies to all projects and folders in 439// the GCP organization. 440// 441// See Enabling CMEK for Logs 442// Router (at /logging/docs/routing/managed-encryption) for more information. 443func (c *ConfigClient) GetCmekSettings(ctx context.Context, req *loggingpb.GetCmekSettingsRequest, opts ...gax.CallOption) (*loggingpb.CmekSettings, error) { 444 md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) 445 ctx = insertMetadata(ctx, c.xGoogMetadata, md) 446 opts = append(c.CallOptions.GetCmekSettings[0:len(c.CallOptions.GetCmekSettings):len(c.CallOptions.GetCmekSettings)], opts...) 447 var resp *loggingpb.CmekSettings 448 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 449 var err error 450 resp, err = c.configClient.GetCmekSettings(ctx, req, settings.GRPC...) 451 return err 452 }, opts...) 453 if err != nil { 454 return nil, err 455 } 456 return resp, nil 457} 458 459// UpdateCmekSettings updates the Logs Router CMEK settings for the given resource. 460// 461// Note: CMEK for the Logs Router can currently only be configured for GCP 462// organizations. Once configured, it applies to all projects and folders in 463// the GCP organization. 464// 465// [UpdateCmekSettings][google.logging.v2.ConfigServiceV2.UpdateCmekSettings] 466// will fail if 1) kms_key_name is invalid, or 2) the associated service 467// account does not have the required 468// roles/cloudkms.cryptoKeyEncrypterDecrypter role assigned for the key, or 469// 3) access to the key is disabled. 470// 471// See Enabling CMEK for Logs 472// Router (at /logging/docs/routing/managed-encryption) for more information. 473func (c *ConfigClient) UpdateCmekSettings(ctx context.Context, req *loggingpb.UpdateCmekSettingsRequest, opts ...gax.CallOption) (*loggingpb.CmekSettings, error) { 474 md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) 475 ctx = insertMetadata(ctx, c.xGoogMetadata, md) 476 opts = append(c.CallOptions.UpdateCmekSettings[0:len(c.CallOptions.UpdateCmekSettings):len(c.CallOptions.UpdateCmekSettings)], opts...) 477 var resp *loggingpb.CmekSettings 478 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 479 var err error 480 resp, err = c.configClient.UpdateCmekSettings(ctx, req, settings.GRPC...) 481 return err 482 }, opts...) 483 if err != nil { 484 return nil, err 485 } 486 return resp, nil 487} 488 489// LogExclusionIterator manages a stream of *loggingpb.LogExclusion. 490type LogExclusionIterator struct { 491 items []*loggingpb.LogExclusion 492 pageInfo *iterator.PageInfo 493 nextFunc func() error 494 495 // Response is the raw response for the current page. 496 // It must be cast to the RPC response type. 497 // Calling Next() or InternalFetch() updates this value. 498 Response interface{} 499 500 // InternalFetch is for use by the Google Cloud Libraries only. 501 // It is not part of the stable interface of this package. 502 // 503 // InternalFetch returns results from a single call to the underlying RPC. 504 // The number of results is no greater than pageSize. 505 // If there are no more results, nextPageToken is empty and err is nil. 506 InternalFetch func(pageSize int, pageToken string) (results []*loggingpb.LogExclusion, nextPageToken string, err error) 507} 508 509// PageInfo supports pagination. See the google.golang.org/api/iterator package for details. 510func (it *LogExclusionIterator) PageInfo() *iterator.PageInfo { 511 return it.pageInfo 512} 513 514// Next returns the next result. Its second return value is iterator.Done if there are no more 515// results. Once Next returns Done, all subsequent calls will return Done. 516func (it *LogExclusionIterator) Next() (*loggingpb.LogExclusion, error) { 517 var item *loggingpb.LogExclusion 518 if err := it.nextFunc(); err != nil { 519 return item, err 520 } 521 item = it.items[0] 522 it.items = it.items[1:] 523 return item, nil 524} 525 526func (it *LogExclusionIterator) bufLen() int { 527 return len(it.items) 528} 529 530func (it *LogExclusionIterator) takeBuf() interface{} { 531 b := it.items 532 it.items = nil 533 return b 534} 535 536// LogSinkIterator manages a stream of *loggingpb.LogSink. 537type LogSinkIterator struct { 538 items []*loggingpb.LogSink 539 pageInfo *iterator.PageInfo 540 nextFunc func() error 541 542 // Response is the raw response for the current page. 543 // It must be cast to the RPC response type. 544 // Calling Next() or InternalFetch() updates this value. 545 Response interface{} 546 547 // InternalFetch is for use by the Google Cloud Libraries only. 548 // It is not part of the stable interface of this package. 549 // 550 // InternalFetch returns results from a single call to the underlying RPC. 551 // The number of results is no greater than pageSize. 552 // If there are no more results, nextPageToken is empty and err is nil. 553 InternalFetch func(pageSize int, pageToken string) (results []*loggingpb.LogSink, nextPageToken string, err error) 554} 555 556// PageInfo supports pagination. See the google.golang.org/api/iterator package for details. 557func (it *LogSinkIterator) PageInfo() *iterator.PageInfo { 558 return it.pageInfo 559} 560 561// Next returns the next result. Its second return value is iterator.Done if there are no more 562// results. Once Next returns Done, all subsequent calls will return Done. 563func (it *LogSinkIterator) Next() (*loggingpb.LogSink, error) { 564 var item *loggingpb.LogSink 565 if err := it.nextFunc(); err != nil { 566 return item, err 567 } 568 item = it.items[0] 569 it.items = it.items[1:] 570 return item, nil 571} 572 573func (it *LogSinkIterator) bufLen() int { 574 return len(it.items) 575} 576 577func (it *LogSinkIterator) takeBuf() interface{} { 578 b := it.items 579 it.items = nil 580 return b 581} 582