Skip to content
Search

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 {} }

[S1000 default] [W] should use for range instead of for { select {} }

Select statements with a single case can be replaced with a simple send or receive.

Before:

select {
case x := <-ch:
    fmt.Println(x)
}

After:

x := <-ch
fmt.Println(x)

error strings should not be capitalized

error strings should not be capitalized (ST1005)

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

[modernize rangeint] [H] for loop can be modernized using range over int

Before:

for i := 0; i < 6; i++ {
}

After:

for i := range 6 {
}

See also

author Zer0 sitemap