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)
  }
}