Top 50 Go Mistakes and How to Avoid Them

Use GODEBUG environment variables or source directives to revert specific Go behaviors and avoid breaking changes during upgrades.

Go prevents common mistakes by using GODEBUG settings to opt-out of breaking changes or revert to older behaviors when upgrading toolchains. You can control specific behaviors like disabling HTTP/2 or allowing panic(nil) by setting the GODEBUG environment variable or adding //go:debug directives to your source files.

export GODEBUG=http2client=0,panicnil=1

Alternatively, add these directives to your go.mod (Go 1.23+) or source files:

//go:debug http2client=0
//go:debug panicnil=1

Verify the active settings with:

go list -f '{{.DefaultGODEBUG}}' ./my/package