The Go SDK is currently in experimental status. If you would like to provide feedback, please reach out to us with your suggestions and comments on our Discord.
Go - Bucket.File.Read()
Read the contents of a file from a bucket.
import (
"context"
"fmt"
"github.com/nitrictech/go-sdk/nitric"
)
func main() {
bucket, err := nitric.NewBucket("bucket-name").Allow(nitric.BucketRead)
if err != nil {
return
}
contents, err := bucket.File("cat.png").Read(context.TODO())
if err != nil {
return
}
fmt.Println(contents)
if err := nitric.Run(); err != nil {
fmt.Println(err)
}
}
Parameters
- Name
ctx
- Required
- Required
- Type
- context
- Description
The context of the call, used for tracing.
Examples
Read a file
import (
"context"
"fmt"
"github.com/nitrictech/go-sdk/nitric"
)
func main() {
bucket, err := nitric.NewBucket("bucket-name").Allow(nitric.BucketRead)
if err != nil {
return
}
contents, err := bucket.File("cat.png").Read(context.TODO())
if err != nil {
return
}
fmt.Println(contents)
if err := nitric.Run(); err != nil {
fmt.Println(err)
}
}