A package for finding and manipulating go.mod
files.
- Recursively traverses up the filesystem looking for
go.mod
- Supports binary builds with
-trimpath
- Extracted from Bud
go get github.com/livebud/mod
func main() {
module, err := mod.Find(".")
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
fmt.Println(module.Directory())
fmt.Println(module.Import())
}
$ go run .
$GOPATH/src/github.com/livebud/mod
github.com/livebud/mod
$ go build -trimpath -ldflags " -X github.com/livebud/mod.path=$(go list -m) -X github.com/livebud/mod.dir=$(go list -m -f {{.Dir}})" .
$ ./main
$GOPATH/src/github.com/livebud/mod
github.com/livebud/mod
- Matt Mueller (@mattmueller)
MIT