Learn to love your compiler
yourbasic.org/golang
The Go compiler sometimes confuses and annoys developers who are new to the language.
This is a list of short articles with strategies and workarounds for common compiler error messages that tend to confuse fresh Go programmers.
-
imported and not used
Programs with unused imports won't compile. -
declared and not used
You must use all local variables. -
multiple-value in single-value context
When a function returns multiple values, you must use all of them. -
syntax error: unexpected newline, expecting comma or }
In a multi-line slice, array or map literal, every line must end with a comma. -
cannot assign to …
Go strings are immutable and behave like read-only byte slices. -
constant overflows int
An untyped constant is converted before it is assigned to a variable. -
syntax error: unexpected ++, expecting expression comma or )
Increment and decrement operations can’t be used as expressions, only as statements. -
syntax error: non-declaration statement outside function body
Short variable declarations can only be used inside functions. -
missing function body for …
An opening brace cannot appear on a line by itself.
Further reading
Tutorials for beginners and experienced developers alike: best practices and production-quality code examples.