Skip to main content
Image

r/golang


"go fix" on Go 1.26+ is awesome
"go fix" on Go 1.26+ is awesome
discussion

If you haven't tried the new "go fix" yet, give it a spin.

It's a proper revival of the old "gofix" idea. In Go 1.26, it was rebuilt on top of the Go analysis framework. So now it can modernize your code with newer language and stdlib features.

It respects the Go version in your module. If your "go.mod" says "go 1.26", it suggests Go 1.26-compatible changes. It doesn't rewrite your code into something your module hasn't opted into.

For teams using LLMs, this is great. You don't need to keep leaving PR comments like “use the newer API here” or “we don't write that pattern anymore.” Run it locally or on the CI instead.

Start from a clean git state:

go fix -diff ./...

Then apply it:

go fix ./...

Then run it again.

Some fixes expose more fixes. The Go team recommends rerunning it, and in practice two passes often catches more than one.

Some useful analyzers:

You can also run one analyzer at a time if you want smaller PRs:

go fix -newexpr ./...
go fix -forvar ./...

That's useful when one pass touches a lot of files and you don't want one giant mixed cleanup patch.

The other neat bit is //go:fix inline. Library authors can use it to help users migrate from old APIs to new APIs. That's much better than deprecating something and hoping everyone reads the changelog.

You can also write your custom analyzer to enforce your own rules. I am writing a few for fun.

The Go blog has two good posts on it:

I ran it on a large RPC service, and "newexpr" cleaned up a pile of pointer helper calls. Extremely satisfying.


Advertisement: Columbus Micro Center is being remodeled with a whole new look and upgrade you’ll love! Sign up for a FREE 128GB Flash Drive
Columbus Micro Center is being remodeled with a whole new look and upgrade you’ll love! Sign up for a FREE 128GB Flash Drive
Image Columbus Micro Center is being remodeled with a whole new look and upgrade you’ll love! Sign up for a FREE 128GB Flash Drive


No matter how many languages I try, I keep returning to Go
No matter how many languages I try, I keep returning to Go
discussion

There are languages similar to Go, but there is something so unique about it that no one can replicate. It's even hard for me to understand as well. I've tried Elixir, Gleam, Rust, Zig, Odin, Java, Scala, and yet, every time I need to build something that I know needs to be good, fast, and well done Go is the language that I pick.

It could be familiarity, but it's really hard to beat the whole Go environment. I think most of the time engineers evaluate things into a single dimension axis either in terms of performance or type system expressiveness, but good code involves so may aspects and Go does surprisingly well in all of them.


Anybody have any advice to dive deeper into go
Anybody have any advice to dive deeper into go

So to preface this I'm dyslexic as fuck, hate reading docs of any form. I know the golang docs are good but really struggle to "connect the dots" with a lot of it. My dyslexia is less like letters jumping around and more can't hold onto the written word past about 2, hence long post.

Are there any concepts or particular sharp edges or things to be aware of. Videos I can digest much easier because they usually do complete examples so I can see the pattern and memorise it. I get the concept eventually because it's about experimenting with the pattern, break it improve it etc. A lot of them are more tutorials and less about "things that will catch you out if you're not aware of them" if that makes sense?

Would appreciate any advice!