Go - Bucket.ListFiles()
Get a list of file keys for files that exist in the bucket.
import ("context""github.com/nitrictech/go-sdk/nitric""github.com/nitrictech/go-sdk/nitric/storage")func main() {bucket := nitric.NewBucket("bucket-name").Allow(storage.BucketRead)files, err := bucket.ListFiles(context.TODO())if err != nil {return}for _, file := range files {contents, err := bucket.Read(context.TODO(), file)if err != nil {continue}// Do something with the file contents}nitric.Run()}
Parameters
- Name
ctx
- Required
- Required
- Type
- context
- Description
The context of the call, used for tracing.
Examples
Deleting all files in a bucket
import ("context""fmt""github.com/nitrictech/go-sdk/nitric""github.com/nitrictech/go-sdk/nitric/storage")func main() {bucket := nitric.NewBucket("bucket-name").Allow(storage.BucketRead)ctx := context.TODO()files, err := bucket.ListFiles(ctx)if err != nil {fmt.Println(err)return}for _, file := range files {bucket.Delete(ctx, file)}nitric.Run()}
Last updated on Nov 8, 2024