|
|
|
|
|
by usrbinbash
1598 days ago
|
|
Easily fixed using lexical scopes: func doThing() string {
result := "OK"
{
var err error
if result, err = somethingElse(); err != nil {
return "ERROR"
}
}
return result
}
`err` is introduced in the lexical scope, `result` isn't so it still refers to the string from the surrounding scope. `err` does not pollute the surrounding scope.You can also try the complete version here: https://go.dev/play/p/kDEB11YdvSs |
|