Created
January 12, 2015 16:40
-
-
Save macu/824efeec5bd6937da19f to your computer and use it in GitHub Desktop.
I hadn't realized you could access variables declared in if statements beyond the first block following the expression. This enables lots of code cleanup :)
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
package main | |
import "fmt" | |
func fab() (int, error) { | |
return 0, nil | |
} | |
func main() { | |
if i, err := fab(); err != nil { | |
// Handle error | |
fmt.Println("err!") | |
} else if i < 0 { | |
// Validate | |
fmt.Println("bad") | |
} else { | |
// Handle value | |
fmt.Println(i) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment