-
Notifications
You must be signed in to change notification settings - Fork 836
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed bugs in Resource Group demo code (#15301)
<!-- Thank you for contributing to the Azure SDK for Go. Please verify the following before submitting your PR, thank you! --> - [ ] The purpose of this PR is explained in this or a referenced issue. - [ ] The PR does not update generated files. - These files are managed by the codegen framework at [Azure/autorest.go][]. - [ ] Tests are included and/or updated for code changes. - [ ] Updates to [CHANGELOG.md][] are included. - [ ] MIT license headers are included in each file. [Azure/autorest.go]: https://github.com/Azure/autorest.go [CHANGELOG.md]: https://github.com/Azure/azure-sdk-for-go/blob/main/CHANGELOG.md
- Loading branch information
1 parent
eb6d24c
commit 438c7e5
Showing
1 changed file
with
11 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -168,10 +168,11 @@ import ( | |
***Define some global variables*** | ||
```go | ||
var ( | ||
ctx = context.Background() | ||
subscriptionId = os.Getenv("AZURE_SUBSCRIPTION_ID") | ||
location = "westus2" | ||
resourceGroupName = "resourceGroupName" | ||
ctx = context.Background() | ||
subscriptionId = os.Getenv("AZURE_SUBSCRIPTION_ID") | ||
location = "westus2" | ||
resourceGroupName = "resourceGroupName" | ||
interval = 5 * time.Second | ||
) | ||
``` | ||
|
||
|
@@ -283,13 +284,13 @@ func main() { | |
if err != nil { | ||
log.Fatalf("cannot create resource group: %+v", err) | ||
} | ||
log.Printf("Resource Group %s created", *resourceGroup.ID) | ||
log.Printf("Resource Group %s created", *resourceGroup.ResourceGroup.ID) | ||
|
||
updatedRG, err := updateResourceGroup(ctx, conn) | ||
if err != nil { | ||
log.Fatalf("cannot update resource group: %+v", err) | ||
} | ||
log.Printf("Resource Group %s updated", *updatedRG.ID) | ||
log.Printf("Resource Group %s updated", *updatedRG.ResourceGroup.ID) | ||
|
||
rgList, err := listResourceGroups(ctx, conn) | ||
if err != nil { | ||
|
@@ -312,20 +313,21 @@ Due to the complexity of this scenario, please [click here](https://aka.ms/azsdk | |
|
||
Long Running Operations | ||
----------------------- | ||
In the samples above, you might notice that some operations has a ``Begin`` prefix (for example, ``BeginDelete``). This indicates the operation is a Long-Running Operation (In short, LRO). For resource managment libraries, this kind of operation is quite common since certain resource operations may take a while to finish. When you need to use those LROs, you will need to use a poller and keep polling for the result until it is done. To illustrate this pattern, here is an example | ||
In the samples above, you might notice that some operations have a ``Begin`` prefix (for example, ``BeginDelete``). This indicates the operation is a Long-Running Operation (LRO). For resource management libraries, this kind of operation is quite common since certain resource operations may take a while to finish. When you need to use those LROs, you will need to use a poller and keep polling for the result until it is done. To illustrate this pattern, here is an example | ||
|
||
```go | ||
poller, err := client.BeginCreate(context.Background(), "resource_identifier", "additonal_parameter") | ||
if err != nil { | ||
// handle error... | ||
} | ||
resp, err = poller.PollUntilDone(context.Background(), 5*time.Second) | ||
resp, err = poller.PollUntilDone(context.Background(), 5 * time.Second) | ||
if err != nil { | ||
// handle error... | ||
} | ||
fmt.Printf("LRO done") | ||
// dealing with `resp` | ||
``` | ||
|
||
Note that you will need to pass a polling interval to ```PollUntilDone``` and tell the poller how often it should try to get the status. This number is usually small but it's best to consult the [Azure service documentation](https://docs.microsoft.com/azure/?product=featured) on best practices and recommdend intervals for your specific use cases. | ||
|
||
For more advanced usage of LRO and design guidelines of LRO, please visit [this documentation here](https://azure.github.io/azure-sdk/golang_introduction.html#methods-invoking-long-running-operations) | ||
|
@@ -364,4 +366,4 @@ our CLA. | |
|
||
This project has adopted the Microsoft Open Source Code of Conduct. For | ||
more information see the Code of Conduct FAQ or contact | ||
<[email protected]> with any additional questions or comments. | ||
[[email protected]](mailto:[email protected]) with any questions or comments. |