Code to install tools using the tools.go pattern
Go has an informal pattern of naming repository targets for tools to install in a project, used in combination with go.mod to handle dependency version.
It looks similar to this:
//go:build tools
// +build tools
package tools
import (
_ "github.com/golangci/golangci-lint/cmd/golangci-lint@v1.42.0"
)Note the //go:build tools/// +build tools directive(s), which makes the compiler skip this particular file. The error of including the specific version at this point doesn't matter; only the textual representation does for the install tool to use it.
First, go install github.com/elisarver/installtools/cmd/go-tool-installer to get the tool and then run go-tool-installer | sh to install the packages.
You can try it in the example directory, which installs a specific version of golangci-lint that you can verify with --version, post-install.