ListDirectoryBuckets list all buckets owned by this authenticated user. This call requires explicit authentication, no anonymous requests are allowed for listing buckets. api := client.New(....) dirBuckets, err := api.ListDirectoryBuckets(context.Background())
(ctx context.Context)
| 66 | // api := client.New(....) |
| 67 | // dirBuckets, err := api.ListDirectoryBuckets(context.Background()) |
| 68 | func (c *Client) ListDirectoryBuckets(ctx context.Context) (iter.Seq2[BucketInfo, error], error) { |
| 69 | fetchBuckets := func(continuationToken string) ([]BucketInfo, string, error) { |
| 70 | metadata := requestMetadata{contentSHA256Hex: emptySHA256Hex} |
| 71 | metadata.queryValues = url.Values{} |
| 72 | metadata.queryValues.Set("max-directory-buckets", "1000") |
| 73 | if continuationToken != "" { |
| 74 | metadata.queryValues.Set("continuation-token", continuationToken) |
| 75 | } |
| 76 | |
| 77 | // Execute GET on service. |
| 78 | resp, err := c.executeMethod(ctx, http.MethodGet, metadata) |
| 79 | defer closeResponse(resp) |
| 80 | if err != nil { |
| 81 | return nil, "", err |
| 82 | } |
| 83 | if resp != nil { |
| 84 | if resp.StatusCode != http.StatusOK { |
| 85 | return nil, "", httpRespToErrorResponse(resp, "", "") |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | results := listAllMyDirectoryBucketsResult{} |
| 90 | if err = xmlDecoder(resp.Body, &results); err != nil { |
| 91 | return nil, "", err |
| 92 | } |
| 93 | |
| 94 | return results.Buckets.Bucket, results.ContinuationToken, nil |
| 95 | } |
| 96 | |
| 97 | return func(yield func(BucketInfo, error) bool) { |
| 98 | var continuationToken string |
| 99 | for { |
| 100 | buckets, token, err := fetchBuckets(continuationToken) |
| 101 | if err != nil { |
| 102 | yield(BucketInfo{}, err) |
| 103 | return |
| 104 | } |
| 105 | for _, bucket := range buckets { |
| 106 | if !yield(bucket, nil) { |
| 107 | return |
| 108 | } |
| 109 | } |
| 110 | if token == "" { |
| 111 | // nothing to continue |
| 112 | return |
| 113 | } |
| 114 | continuationToken = token |
| 115 | } |
| 116 | }, nil |
| 117 | } |
| 118 | |
| 119 | // Bucket List Operations. |
| 120 | func (c *Client) listObjectsV2(ctx context.Context, bucketName string, opts ListObjectsOptions) iter.Seq[ObjectInfo] { |
no test coverage detected