-
Notifications
You must be signed in to change notification settings - Fork 216
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix error about passing by value in for range
#4556
Fix error about passing by value in for range
#4556
Conversation
Azure Dev CLI Install InstructionsInstall scriptsMacOS/Linux
bash:
pwsh:
WindowsPowerShell install
MSI install
Standalone Binary
MSI
Documentationlearn.microsoft.com documentationtitle: Azure Developer CLI reference
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thanks for the fix!
@@ -186,7 +186,8 @@ func infraSpec(projectConfig *ProjectConfig) (*scaffold.InfraSpec, error) { | |||
} | |||
|
|||
// create reverse frontends -> backends mapping | |||
for _, svc := range infraSpec.Services { | |||
for i := range infraSpec.Services { | |||
svc := &infraSpec.Services[i] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer re-assigning infraSpec.Services[i] = svc
, better than mutating the element directly. You can make any changes to the instance copy and persist at the end. This would prevent leaving the original element at invalid states if there's an error during the updating process.
Maybe that wouldn't happen here because there are not too many changes to svc
, but in general, as a good practice, updating an element from a map or slice is better by updating a copy and when ready, re-assigning.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the thinking about atomic guarantees, this is definitely a good thing to think about as another step of increasing "safety", but I don't think this will affect us meaningfully in this particular scenario. We can discuss more during our team chats!
Fix error about passing by value in
for range
.Refs: https://go.dev/wiki/Range