Skip to content

Commit

Permalink
feat(post): go tools
Browse files Browse the repository at this point in the history
  • Loading branch information
fredrikaverpil committed Dec 2, 2024
1 parent 97851fb commit 7524857
Showing 1 changed file with 113 additions and 0 deletions.
113 changes: 113 additions & 0 deletions mkdocs/blog/posts/2024-12-02-go-tools.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
---
date: 2024-11-02
draft: false
authors:
- fredrikaverpil
comments: true
tags:
- golang
---

# Managing tools in Go projects

There are
[some exciting news](https://github.com/golang/go/issues/48429#issuecomment-2499281711)
in the Go community as of recently on how to manage tools in Go projects. With
the next release of Go (1.24) it seems we'll finally be able to define
per-project tools! 🎉

## Giving it a spin with `gotip`

You can try it out today using
[`gotip`](https://pkg.go.dev/golang.org/dl/gotip):

```bash
go install golang.org/dl/gotip@latest
gotip download
```

Then let's create a project:

```bash
gotip mod init go-playground
gotip get -tool github.com/alta/protopatch/cmd/protoc-gen-go-patch
gotip get -tool gotest.tools/gotestsum

```

There's a new `tool` section in the `go.mod`!

```gomod
$ cat go.mod
module go-playground
go 1.24
tool (
github.com/alta/protopatch/cmd/protoc-gen-go-patch
gotest.tools/gotestsum
)
require (
github.com/alta/protopatch v0.5.3 // indirect
github.com/bitfield/gotestdox v0.2.2 // indirect
github.com/dnephin/pflag v1.0.7 // indirect
github.com/fatih/color v1.16.0 // indirect
github.com/fatih/structtag v1.2.0 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
golang.org/x/mod v0.16.0 // indirect
golang.org/x/sync v0.6.0 // indirect
golang.org/x/sys v0.18.0 // indirect
golang.org/x/term v0.18.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/tools v0.19.0 // indirect
google.golang.org/protobuf v1.31.0 // indirect
gotest.tools/gotestsum v1.12.0 // indirect
)
```

You can now run tools like this:

```bash
gotip tool <the-tool>
```

And you can also see which bundled tools are available:

```bash
$ gotip tool

addr2line
asm
buildid
cgo
compile
covdata
cover
dist
distpack
doc
fix
link
nm
objdump
pack
pprof
preprofile
test2json
trace
vet
```

Key Points:

- Native tools management starting with
[Go 1.24](https://tip.golang.org/doc/go1.24), expected to be released in
January 2025.
- Improves from the traditional ideoms (`Makefile` and/or `tools.go`) and
decreases complexity to define tools.
- Very likely works out of the box with dependency management tools like
Dependabot.

0 comments on commit 7524857

Please sign in to comment.