Notes from learning the fundamentals of the Go programming language from this amazing tutorial. It is a fantastic video tutorial on YouTube that explains Go concepts from the ground up and offers some great insight into the language design
var
keyword or the shorthand :=
(only inside of functions / methods to simplify parsing!).
var a int
// or
a := 2 // in functions or methods
%d %[1]v
will reuse the first passed in argument (e.g. if we want to print a single variable twice in a Printf, you’d normally do fmt.Printf("%d %d", a, a)
, but with this you just need to do fmt.Printf("%d %[1]v", a)
and that parameter a
will be reused)const(
a = 1
b = 3 * 100
s = "hello"
)
byte
is a synonym for uint8
rune
is a synonym for int32
for charactersstring
is an immutable sequence of “characters”
runes
\n
)
`string with "quotes"`
string
is the number of UTF-8 bytes required to encode it, NOT THE NUMBER OF LOGICAL CHARACTERSstrings
package contains useful string functions==
, slices are obviously not. Arrays can be used as map keys, slices cannotcopy
and append
helper operatorsvar m map[string]int // nil map (reading any key will return nil)
_m = make(map[string]int) // empty non-nil map