Zero Values

Go default values, AKA “zero values” are the values that are given when a variable has been created but not given a value.

TypeZero Value
String""
Number0
BooleanFalse
Everything elsenil

Comma OK Idiom

Go allows you to reuse variable names in certain scenarios. Most commonly when checking for errors with multiple err variables, or checking for errors with ok variables.

a, ok := checkOK()
if !ok {
	panic()
}
c, ok := checkOK()
if !ok {
	panic()
}
 
// this is ok even though it looks like b is being used twice, useful for when you have multiple return values and need to check if there is an error
 
a, err := ...
if err != nil {
	// handle first error
}
b, err := ...

Constants

Go has constants that work exactly how you’d expect them to.

const NameCapitalFirst = "don't use a colon for constants"