You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your feature request related to a problem? Please describe.
Bucket.List() is somewhat cumbersome to use since it was designed long before Go 1.23. Now that Go 1.23 standardized what iterators should look like, there's an opportunity to design simpler iteration APIs.
func (i*ListIterator) All(ctx context.Context, err*error) iter.Seq2[*ListObject, func(io.Writer)]
// Note: The iter.Seq2 type cannot be used until Go CDK phases out support for Go versions older than 1.23.// For the time being, this function will need to return func(func(*ListObject, func(io.Writer)) bool)
Consumes the remaining objects in the ListIterator. The second value is a convenient way to call Bucket.Download() on the current object without the typical overhead of error handling, as this is already handled by All()
varerrerroriter:=bucket.List(options)
forobj, download:=rangeiter.All(ctx, &err) {
fmt.Println(obj.Key)
ifobj.Size<1024 {
varbuf bytes.Bufferdownload(&buf)
fmt.Println(buf.String())
}
}
// loop terminates early on erroriferr!=nil {
// also happens if download() fails or ctx is cancelledlog.Fatal(err)
}
Option 2: Bucket.All()
Avoids the need for the ListIterator object entirely.
One potential downside to this is that if a standard io.FS.All() method is ever introduced, it will almost certainly have an incompatible signature with whatever is decided here. It seems safer to avoid adding iterator methods directly to Bucket at this time.
The text was updated successfully, but these errors were encountered:
Is your feature request related to a problem? Please describe.
Bucket.List()
is somewhat cumbersome to use since it was designed long before Go 1.23. Now that Go 1.23 standardized what iterators should look like, there's an opportunity to design simpler iteration APIs.For details, see https://go.dev/blog/range-functions
Describe the solution you'd like
Option 1:
ListIterator.All()
Consumes the remaining objects in the
ListIterator
. The second value is a convenient way to callBucket.Download()
on the current object without the typical overhead of error handling, as this is already handled byAll()
Option 2:
Bucket.All()
Avoids the need for the
ListIterator
object entirely.One potential downside to this is that if a standard
io.FS.All()
method is ever introduced, it will almost certainly have an incompatible signature with whatever is decided here. It seems safer to avoid adding iterator methods directly toBucket
at this time.The text was updated successfully, but these errors were encountered: