Go: Random Language Notes
Some random notes about the Go language.
Commas in Expression Case Statements
The use of comma in case statements work for expression:
x := 2
switch {
case x == 1, x == 2:
fmt.Println("x < 3")
default:
fmt.Println("x >= 3")
}
If x
is 1 or 2, the x < 3
will be printed out.
Lookups On A Nil Map
You can do lookups on a nil
map:
var xs map[string]string = nil
x, hasX := xs["hello"]
The result will simply be the zero value of the particular type. In this case x
will be the empty string.