()
| 319 | } |
| 320 | |
| 321 | func ExampleBucket_ListPage() { |
| 322 | // Connect to a bucket when your program starts up. |
| 323 | // This example uses the file-based implementation. |
| 324 | dir, cleanup := newTempDir() |
| 325 | defer cleanup() |
| 326 | |
| 327 | // Create the file-based bucket. |
| 328 | bucket, err := fileblob.OpenBucket(dir, nil) |
| 329 | if err != nil { |
| 330 | log.Fatal(err) |
| 331 | } |
| 332 | defer bucket.Close() |
| 333 | |
| 334 | // Create some blob objects for listing: "foo[0..7].txt". |
| 335 | ctx := context.Background() |
| 336 | for i := range 8 { |
| 337 | if err := bucket.WriteAll(ctx, fmt.Sprintf("foo%d.txt", i), []byte("Go Cloud Development Kit"), nil); err != nil { |
| 338 | log.Fatal(err) |
| 339 | } |
| 340 | } |
| 341 | |
| 342 | // Iterate over them in pages. |
| 343 | // This will list the blobs created above because fileblob is strongly |
| 344 | // consistent, but is not guaranteed to work on all services. |
| 345 | |
| 346 | // The first page of 3 results. |
| 347 | objs, token, err := bucket.ListPage(ctx, blob.FirstPageToken, 3, nil) |
| 348 | if err != nil { |
| 349 | log.Fatal(err) |
| 350 | } |
| 351 | for _, obj := range objs { |
| 352 | fmt.Println(obj.Key) |
| 353 | } |
| 354 | fmt.Println("END OF PAGE 1") |
| 355 | |
| 356 | // The second page of 3 results. |
| 357 | objs, token, err = bucket.ListPage(ctx, token, 3, nil) |
| 358 | if err != nil { |
| 359 | log.Fatal(err) |
| 360 | } |
| 361 | for _, obj := range objs { |
| 362 | fmt.Println(obj.Key) |
| 363 | } |
| 364 | fmt.Println("END OF PAGE 2") |
| 365 | |
| 366 | // The third page with the last 2 results. |
| 367 | objs, token, err = bucket.ListPage(ctx, token, 3, nil) |
| 368 | if err != nil { |
| 369 | log.Fatal(err) |
| 370 | } |
| 371 | for _, obj := range objs { |
| 372 | fmt.Println(obj.Key) |
| 373 | } |
| 374 | fmt.Println("END OF PAGE 3") |
| 375 | |
| 376 | // There are no more pages, so token is now nil. Calling ListPage again will return io.EOF. |
| 377 | if token != nil { |
| 378 | fmt.Println("Token was not nil.") |
nothing calls this directly
no test coverage detected