Looking to do something like this
curr := foo()["blah"].(string)
curr, err := strconv.ParseFloat(curr, 64)
ERROR: cannot assign float64 to curr (type string) in multiple assignment
I dont want to make another temporary variable that I won't use after the conversion. I'm fairly new to Go so is there an approach that will help me avoid
temp := foo()["blah"].(string)
curr, err := strconv.ParseFloat(temp, 64)
You are trying to force duck-typing here, and Go is statically-typed so that's going to be hairy or impossible. This justifies having another variable:
if temp, ok := foo()["blah"].(string); ok {
curr, err := strconv.ParseFloat(temp, 64)
if err != nil {
panic(err)
}
}
Go garbage collector is pretty sick. Having an extra variable temp
for a few lines isn't that bad. Also don't forget guarding over type assertion.