Skip to content

Commit

Permalink
implement list containers
Browse files Browse the repository at this point in the history
  • Loading branch information
jpicht committed Mar 14, 2022
1 parent 39e0895 commit 2806e23
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions actions/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package actions
import (
"context"
"encoding/json"
"fmt"
"os"
"text/template"
"time"
Expand Down Expand Up @@ -30,6 +31,29 @@ type blobInfo struct {
type renderFunc func(*blobInfo)

func List(containerName, prefix string, client *azblob.ServiceClient) {
if containerName == "" {
ListContainers(client)
} else {
ListBlobs(containerName, prefix, client)
}
}

func ListContainers(client *azblob.ServiceClient) {
pager := client.ListContainers(nil)

if pager.Err() != nil {
log.WithError(pager.Err()).Fatal("Cannot list containers")
}

for pager.NextPage(context.TODO()) {
for _, container := range pager.PageResponse().ContainerItems {
fmt.Println(*container.Name)
}
}
}

func ListBlobs(containerName, prefix string, client *azblob.ServiceClient) {

containerClient := client.NewContainerClient(containerName)

pager := containerClient.ListBlobsFlat(&azblob.ContainerListBlobFlatSegmentOptions{
Expand Down

0 comments on commit 2806e23

Please sign in to comment.