-
Notifications
You must be signed in to change notification settings - Fork 17
/
buckets.go
64 lines (52 loc) · 1.62 KB
/
buckets.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// Copyright (C) 2020 Storj Labs, Inc.
// See LICENSE for copying information.
package uplink
import (
"context"
"storj.io/uplink/private/metaclient"
)
// ListBucketsOptions defines bucket listing options.
type ListBucketsOptions struct {
// Cursor sets the starting position of the iterator. The first item listed will be the one after the cursor.
Cursor string
}
// ListBuckets returns an iterator over the buckets.
func (project *Project) ListBuckets(ctx context.Context, options *ListBucketsOptions) *BucketIterator {
defer mon.Task()(&ctx)(nil)
if options == nil {
options = &ListBucketsOptions{}
}
buckets := BucketIterator{
iterator: metaclient.IterateBuckets(ctx, metaclient.IterateBucketsOptions{
Cursor: options.Cursor,
DialClientFunc: func() (*metaclient.Client, error) {
return project.dialMetainfoClient(ctx)
},
}),
}
return &buckets
}
// BucketIterator is an iterator over a collection of buckets.
type BucketIterator struct {
iterator *metaclient.BucketIterator
}
// Next prepares next Bucket for reading.
// It returns false if the end of the iteration is reached and there are no more buckets, or if there is an error.
func (buckets *BucketIterator) Next() bool {
return buckets.iterator.Next()
}
// Err returns error, if one happened during iteration.
func (buckets *BucketIterator) Err() error {
return convertKnownErrors(buckets.iterator.Err(), "", "")
}
// Item returns the current bucket in the iterator.
func (buckets *BucketIterator) Item() *Bucket {
item := buckets.iterator.Item()
if item == nil {
return nil
}
return &Bucket{
Name: item.Name,
Created: item.Created,
}
}