-
Notifications
You must be signed in to change notification settings - Fork 1
/
create_container.go
52 lines (39 loc) · 1.21 KB
/
create_container.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package main
import (
"context"
"log"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/storage/azblob"
)
// Blob dev guide create container sample
func handleError(err error) {
if err != nil {
log.Fatal(err.Error())
}
}
// <snippet_create_container>
func createContainer(client *azblob.Client, containerName string) {
// Create a container
_, err := client.CreateContainer(context.TODO(), containerName, nil)
handleError(err)
}
// </snippet_create_container>
// <snippet_create_root_container>
func createRootContainer(client *azblob.Client) {
// Create root container
_, err := client.CreateContainer(context.TODO(), "$root", nil)
handleError(err)
}
// </snippet_create_root_container>
// Replace the existing main function with the corrected code
func main() {
// TODO: replace <storage-account-name> with your actual storage account name
url := "https://<storage-account-name>.blob.core.windows.net/"
credential, err := azidentity.NewDefaultAzureCredential(nil)
handleError(err)
client, err := azblob.NewClient(url, credential, nil)
handleError(err)
containerName := "sample-container"
createContainer(client, containerName)
createRootContainer(client)
}