Skip to content

Commit 8aa9b2e

Browse files
azblob doc.go fix (Azure#20825)
* Updating doc.go
1 parent 5e6fb6f commit 8aa9b2e

File tree

1 file changed

+20
-23
lines changed

1 file changed

+20
-23
lines changed

sdk/storage/azblob/doc.go

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -51,19 +51,20 @@ Use the key as the credential parameter to authenticate the client:
5151
cred, err := azblob.NewSharedKeyCredential(accountName, accountKey)
5252
handle(err)
5353
54-
serviceClient, err := azblob.NewServiceClientWithSharedKey(serviceURL, cred, nil)
54+
serviceClient, err := azblob.NewClientWithSharedKeyCredential(serviceURL, cred, nil)
5555
handle(err)
5656
5757
fmt.Println(serviceClient.URL())
5858
5959
Using a Connection String
6060
6161
Depending on your use case and authorization method, you may prefer to initialize a client instance with a connection string instead of providing the account URL and credential separately.
62-
To do this, pass the connection string to the service client's `NewServiceClientFromConnectionString` method.
62+
To do this, pass the connection string to the service client's `NewClientFromConnectionString` method.
6363
The connection string can be found in your storage account in the Azure Portal under the "Access Keys" section.
6464
6565
connStr := "DefaultEndpointsProtocol=https;AccountName=<my_account_name>;AccountKey=<my_account_key>;EndpointSuffix=core.windows.net"
66-
serviceClient, err := azblob.NewServiceClientFromConnectionString(connStr, nil)
66+
serviceClient, err := azblob.NewClientFromConnectionString(connStr, nil)
67+
handle(err)
6768
6869
Using a Shared Access Signature (SAS) Token
6970
@@ -82,20 +83,20 @@ You can generate a SAS token from the Azure Portal under Shared Access Signature
8283
8384
cred, err := azblob.NewSharedKeyCredential(accountName, accountKey)
8485
handle(err)
85-
serviceClient, err := azblob.NewServiceClientWithSharedKey(serviceURL, cred, nil)
86+
serviceClient, err := azblob.NewClientWithSharedKeyCredential(serviceURL, cred, nil)
8687
handle(err)
8788
fmt.Println(serviceClient.URL())
8889
8990
// Alternatively, you can create SAS on the fly
9091
91-
resources := azblob.AccountSASResourceTypes{Service: true}
92-
permission := azblob.AccountSASPermissions{Read: true}
92+
resources := sas.AccountResourceTypes{Service: true}
93+
permission := sas.AccountPermissions{Read: true}
9394
start := time.Now()
9495
expiry := start.AddDate(0, 0, 1)
95-
serviceURLWithSAS, err := serviceClient.GetSASURL(resources, permission, start, expiry)
96+
serviceURLWithSAS, err := serviceClient.ServiceClient().GetSASURL(resources, permission, expiry, &service.GetSASURLOptions{StartTime: &start})
9697
handle(err)
9798
98-
serviceClientWithSAS, err := azblob.NewServiceClientWithNoCredential(serviceURLWithSAS, nil)
99+
serviceClientWithSAS, err := azblob.NewClientWithNoCredential(serviceURLWithSAS, nil)
99100
handle(err)
100101
101102
fmt.Println(serviceClientWithSAS.URL())
@@ -135,13 +136,13 @@ Examples
135136
handle(err)
136137
137138
// The service URL for blob endpoints is usually in the form: http(s)://<account>.blob.core.windows.net/
138-
serviceClient, err := azblob.NewServiceClientWithSharedKey(fmt.Sprintf("https://%s.blob.core.windows.net/", accountName), cred, nil)
139+
serviceClient, err := azblob.NewClientWithSharedKeyCredential(fmt.Sprintf("https://%s.blob.core.windows.net/", accountName), cred, nil)
139140
handle(err)
140141
141142
// ===== 1. Create a container =====
142143
143144
// First, create a container client, and use the Create method to create a new container in your account
144-
containerClient, err := serviceClient.NewContainerClient("testcontainer")
145+
containerClient := serviceClient.ServiceClient().NewContainerClient("testcontainer")
145146
handle(err)
146147
147148
// All APIs have an options' bag struct as a parameter.
@@ -154,13 +155,13 @@ Examples
154155
uploadData := "Hello world!"
155156
156157
// Create a new blockBlobClient from the containerClient
157-
blockBlobClient, err := containerClient.NewBlockBlobClient("HelloWorld.txt")
158+
blockBlobClient := containerClient.NewBlockBlobClient("HelloWorld.txt")
158159
handle(err)
159160
160161
// Upload data to the block blob
161-
blockBlobUploadOptions := azblob.BlockBlobUploadOptions{
162-
Metadata: map[string]string{"Foo": "Bar"},
163-
TagsMap: map[string]string{"Year": "2022"},
162+
blockBlobUploadOptions := blockblob.UploadOptions{
163+
Metadata: map[string]*string{"Foo": to.Ptr("Bar")},
164+
Tags: map[string]string{"Year": "2022"},
164165
}
165166
_, err = blockBlobClient.Upload(context.TODO(), streaming.NopCloser(strings.NewReader(uploadData)), &blockBlobUploadOptions)
166167
handle(err)
@@ -175,10 +176,9 @@ Examples
175176
downloadData, err := io.ReadAll(reader)
176177
handle(err)
177178
if string(downloadData) != uploadData {
178-
handle(errors.New("Uploaded data should be same as downloaded data"))
179+
handle(errors.New("uploaded data should be same as downloaded data"))
179180
}
180181
181-
182182
if err = reader.Close(); err != nil {
183183
handle(err)
184184
return
@@ -189,18 +189,15 @@ Examples
189189
// To iterate over a page use the NextPage(context.Context) to fetch the next page of results.
190190
// PageResponse() can be used to iterate over the results of the specific page.
191191
// Always check the Err() method after paging to see if an error was returned by the pager. A pager will return either an error or the page of results.
192-
pager := containerClient.ListBlobsFlat(nil)
193-
for pager.NextPage(context.TODO()) {
194-
resp := pager.PageResponse()
192+
pager := containerClient.NewListBlobsFlatPager(nil)
193+
for pager.More() {
194+
resp, err := pager.NextPage(context.TODO())
195+
handle(err)
195196
for _, v := range resp.Segment.BlobItems {
196197
fmt.Println(*v.Name)
197198
}
198199
}
199200
200-
if err = pager.Err(); err != nil {
201-
handle(err)
202-
}
203-
204201
// Delete the blob.
205202
_, err = blockBlobClient.Delete(context.TODO(), nil)
206203
handle(err)

0 commit comments

Comments
 (0)