forked from Azure-Samples/azure-sdk-for-go-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
blob.go
32 lines (26 loc) · 956 Bytes
/
blob.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// Copyright (c) Microsoft and contributors. All rights reserved.
//
// This source code is licensed under the MIT license found in the
// LICENSE file in the root directory of this source tree.
package storage
import (
"context"
"io/ioutil"
blob "github.com/Azure/azure-storage-blob-go/2016-05-31/azblob"
)
func getBlobURL(ctx context.Context, accountName, containerName, blobName string) blob.BlobURL {
container := getContainerURL(ctx, accountName, containerName)
blob := container.NewBlobURL(blobName)
return blob
}
// GetBlob downloads the specified blob contents
func GetBlob(ctx context.Context, accountName, containerName, blobName string) (string, error) {
b := getBlobURL(ctx, accountName, containerName, blobName)
resp, err := b.GetBlob(ctx, blob.BlobRange{}, blob.BlobAccessConditions{}, false)
if err != nil {
return "", err
}
defer resp.Body().Close()
body, err := ioutil.ReadAll(resp.Body())
return string(body), err
}