Skip to content

Latest commit

 

History

History
54 lines (39 loc) · 1 KB

Readme.md

File metadata and controls

54 lines (39 loc) · 1 KB

Mod

Go Reference

A package for finding and manipulating go.mod files.

Features

  • Recursively traverses up the filesystem looking for go.mod
  • Supports binary builds with -trimpath
  • Extracted from Bud

Install

go get github.com/livebud/mod

Example

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

Binary with -trimpath

$ 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

Contributors

License

MIT