2
0
mirror of https://github.com/chubin/cheat.sheets synced 2024-11-07 09:20:22 +00:00
cheat.sheets/sheets/go/if
2017-05-08 20:27:00 +00:00

24 lines
325 B
Plaintext

func main() {
// Basic one
if x > 0 {
return x
} else {
return -x
}
// You can put one statement before the condition
if a := b + c; a < 42 {
return a
} else {
return a - 42
}
// Type assertion inside if
var val interface{}
val = "foo"
if str, ok := val.(string); ok {
fmt.Println(str)
}
}