Types
Go is statically typed, which means all variable types are known before the code runs, which is very nice since it ensures the code is type safe and can catch type-related errors at compile time.
Besides the most basic types that are common to most languages, such as int, string, bool, etc, Go has some unique types for specific use cases: rune (for Unicode code points), byte (alias for uint8), and complex64/128 (for complex numbers) are some examples.
TIP
You should always prefer using the default types (
int,float64, etc) unless you have a specific reason to use a different type or size.
TIP
Use
runewhen you need to work with Unicode characters, as it represents a single Unicode code point and is more efficient than usingstringfor individual characters.
NOTE
Notice that you can specify a number along with the type, such as
int32orfloat64, this controls the size of the type and how much memory (in bits) it occupies. It can be pretty useful when you need to optimize for performance or memory usage.