TL;DR: Use a tools.go
file with //go:build tools
to list import _ "github.com/octocat/somedevtool"
to stop go mod tidy
from removing them.
//go:build tools package tools import ( _ "github.com/melbahja/got/cmd/got" _ "github.com/arkady-emelyanov/go-shellparse"
)
💡 go mod tidy
doesn’t care if the package is cmd or lib
Then you can use whatever you list in tools.go
in //go:generate
and task.go
!
//go:generate -command got go run github.com/melbahja/got/cmd/got package main import "fmt" //go:generate got https://example.org/ func main() { // ...
}
// task.go
//go:build ignore package main import "github.com/arkady-emelyanov/go-shellparse" func main() { // ...
}
Other resources
Discover more from Coursity
Subscribe to get the latest posts sent to your email.