Go:Warnings
lastmod 2025-11-06created 2025-11-056 edits
How to get rid of the nasty smells in Go code. Mostly reported by coc-go or GoLand.
should use for range instead of for { select {} }
Select statements with a single case can be replaced with a simple send or receive.
Before:
After:
error strings should not be capitalized
There are various opinions, such as that it makes using regex easier and that it keeps error chains consistent.
for loop can be modernized using range over int
Before:
After:
See also
- go
- coc-go
- GoLand
- Staticcheck
- modernize