|
| 1 | +# Guide to migrate from `azure-storage-blob-go` to `azblob` |
| 2 | + |
| 3 | +This guide is intended to assist in the migration from the `azure-storage-blob-go` module, or previous betas of `azblob`, to the latest releases of the `azblob` module. |
| 4 | + |
| 5 | +## Simplified API surface area |
| 6 | + |
| 7 | +The redesign of the `azblob` module separates clients into various sub-packages. |
| 8 | +In previous versions, the public surface area was "flat", so all clients and supporting types were in the `azblob` package. |
| 9 | +This made it difficult to navigate the public surface area. |
| 10 | + |
| 11 | +## Clients |
| 12 | + |
| 13 | +In `azure-storage-blob-go` a client constructor always requires a `url.URL` and `Pipeline` parameters. |
| 14 | + |
| 15 | +In `azblob` a client constructor always requires a `string` URL, any specified credential type, and a `*ClientOptions` for optional values. You pass `nil` to accept default options. |
| 16 | + |
| 17 | +```go |
| 18 | +// new code |
| 19 | +client, err := azblob.NewClient("<my storage account URL>", cred, nil) |
| 20 | +``` |
| 21 | + |
| 22 | +## Authentication |
| 23 | + |
| 24 | +In `azure-storage-blob-go` you created a `Pipeline` with the required credential type. This pipeline was then passed to the client constructor. |
| 25 | + |
| 26 | +In `azblob`, you pass the required credential directly to the client constructor. |
| 27 | + |
| 28 | +```go |
| 29 | +// new code. cred is an AAD token credential created from the azidentity module |
| 30 | +client, err := azblob.NewClient("<my storage account URL>", cred, nil) |
| 31 | +``` |
| 32 | + |
| 33 | +The `azure-storage-blob-go` module provided limited support for OAuth token authentication via `NewTokenCredential`. |
| 34 | +This been replaced by using Azure Identity credentials from [azidentity](https://pkg.go.dev/github.com/Azure/azure-sdk-for-go/sdk/azidentity#section-readme). |
| 35 | + |
| 36 | +Authentication with a shared key via `NewSharedKeyCredential` remains unchanged. |
| 37 | + |
| 38 | +In `azure-storage-blob-go` you created a `Pipeline` with `NewAnonymousCredential` to support anonymous or SAS authentication. |
| 39 | + |
| 40 | +In `azblob` you use the construtor `NewClientWithNoCredential()` instead. |
| 41 | + |
| 42 | +```go |
| 43 | +// new code |
| 44 | +client, err := azblob.NewClientWithNoCredential("<public blob or blob with SAS URL>", nil) |
| 45 | +``` |
| 46 | + |
| 47 | +## Listing blobs/containers |
| 48 | + |
| 49 | +In `azure-storage-blob-go` you explicitly created a `Marker` type that was used to page over results ([example](https://pkg.go.dev/github.com/Azure/azure-storage-blob-go/azblob?utm_source=godoc#example-package)). |
| 50 | + |
| 51 | +In `azblob`, operations that return paginated values return a `*runtime.Pager[T]`. |
| 52 | + |
| 53 | +```go |
| 54 | +// new code |
| 55 | +pager := client.NewListBlobsFlatPager("my-container", nil) |
| 56 | +for pager.More() { |
| 57 | + page, err := pager.NextPage(context.TODO()) |
| 58 | + // process results |
| 59 | +} |
| 60 | +``` |
| 61 | + |
| 62 | +## Configuring the HTTP pipeline |
| 63 | + |
| 64 | +In `azure-storage-blob-go` you explicitly created a HTTP pipeline with configuration before creating a client. |
| 65 | +This pipeline instance was then passed as an argument to the client constructor ([example](https://pkg.go.dev/github.com/Azure/azure-storage-blob-go/azblob?utm_source=godoc#example-NewPipeline)). |
| 66 | + |
| 67 | +In `azblob` a HTTP pipeline is created during client construction. The pipeline is configured through the `azcore.ClientOptions` type. |
| 68 | + |
| 69 | +```go |
| 70 | +// new code |
| 71 | +client, err := azblob.NewClient(account, cred, &azblob.ClientOptions{ |
| 72 | + ClientOptions: azcore.ClientOptions{ |
| 73 | + // configure HTTP pipeline options here |
| 74 | + }, |
| 75 | +}) |
| 76 | +``` |
0 commit comments