Go's compiler is strict on purpose: unused variables and imports are errors, not warnings. Its runtime panics are blunt too. Here are the errors most Go developers hit in their first few months, grouped by when they happen.
Compile time: the compiler is being strict
declared and not used / "fmt" imported and not used
Go refuses to compile code with unused variables or imports. While debugging, assign to the blank identifier or let your editor manage imports:
_ = result // temporary: silence "declared and not used"
Enter fullscreen mode
Exit fullscreen mode
goimports or gopls adds and removes imports automatically on save.
no new variables on left side of :=
:= declares variables. If every name on the left already exists in that scope, use = . With several names, := works as long as at least one is new, which is why x, err := f() works on a second line that introduces x .
undefined: X
The name doesn't exist in this package or isn't exported.…