duration := 1 * time.Hour
if true {
duration, err := time.ParseDuration("5s")
_ = duration // if I don't have this, it gives me a duration declared not used error
if err != nil {
log.Fatal(err)
}
}
fmt.Println(duration) // prints 1 hour
I guess the issue here is that duration is declared again as local var within if statement. Is there a syntactically good way to resolve this?