Go - Bucket.Files()

Get a list of file references for files that exist in the bucket.

import (
"context"
"fmt"
"github.com/nitrictech/go-sdk/nitric"
)
func main() {
bucket, err := nitric.NewBucket("bucket-name").With(nitric.BucketReading)
if err != nil {
return
}
files, err := bucket.Files(context.TODO())
if err != nil {
return
}
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"
)
func main() {
bucket, err := nitric.NewBucket("bucket-name").With(nitric.BucketReading)
if err != nil {
return
}
ctx := context.TODO()
files, err := bucket.Files(ctx)
if err != nil {
fmt.Println(err)
return
}
for _, file := range files {
file.Delete(ctx)
}
nitric.Run()
}

Notes

This method returns a list of File references that exist on the bucket.

Last updated on Oct 11, 2024