Skip to content

Instantly share code, notes, and snippets.

@DipandaAser
Last active January 21, 2022 15:57
Show Gist options
  • Save DipandaAser/76b38fba49ae724b47d4be7145806edc to your computer and use it in GitHub Desktop.
Save DipandaAser/76b38fba49ae724b47d4be7145806edc to your computer and use it in GitHub Desktop.

Revisions

  1. DipandaAser revised this gist Jan 21, 2022. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion storage.go
    Original file line number Diff line number Diff line change
    @@ -22,7 +22,7 @@ func ListFolderObjects(client *s3.Client, bucket string, prefix string) []types.
    break
    }

    page, _ := paginator.NextPage(context.TODO())
    page, err := paginator.NextPage(context.TODO())
    if err != nil && page.Contents != nil {
    objects = append(objects, page.Contents...)
    }
  2. DipandaAser revised this gist Nov 8, 2021. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion storage.go
    Original file line number Diff line number Diff line change
    @@ -23,7 +23,7 @@ func ListFolderObjects(client *s3.Client, bucket string, prefix string) []types.
    }

    page, _ := paginator.NextPage(context.TODO())
    if page.Contents != nil {
    if err != nil && page.Contents != nil {
    objects = append(objects, page.Contents...)
    }
    }
  3. DipandaAser revised this gist Nov 8, 2021. No changes.
  4. DipandaAser created this gist Nov 8, 2021.
    32 changes: 32 additions & 0 deletions storage.go
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,32 @@
    package storage

    import (
    "context"
    _ "github.com/aws/aws-sdk-go-v2/feature/s3/manager"
    "github.com/aws/aws-sdk-go-v2/service/s3"
    "github.com/aws/aws-sdk-go-v2/service/s3/types"
    _ "github.com/aws/aws-sdk-go-v2/service/s3/types"
    )


    func ListFolderObjects(client *s3.Client, bucket string, prefix string) []types.Object {

    paginator := s3.NewListObjectsV2Paginator(client, &s3.ListObjectsV2Input{
    Bucket: &bucket,
    Prefix: &prefix,
    })

    objects := []types.Object{}
    for {
    if !paginator.HasMorePages() {
    break
    }

    page, _ := paginator.NextPage(context.TODO())
    if page.Contents != nil {
    objects = append(objects, page.Contents...)
    }
    }

    return objects
    }