mod

package module
v0.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 7, 2023 License: MIT Imports: 9 Imported by: 0

README

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrFileNotFound = fmt.Errorf(`mod: unable to find "go.mod": %w`, fs.ErrNotExist)

ErrFileNotFound occurs when no go.mod can be found

Functions

func Lookup

func Lookup(directory string) (path string, err error)

Lookup finds the absolute path of the go.mod file in the given directory

Types

type Module

type Module struct {
	fs.FS
	// contains filtered or unexported fields
}

func Find

func Find(directory string) (*Module, error)

func New

func New(dir string) *Module

New module

func Parse

func Parse(path string, data []byte) (*Module, error)

Parse a go.mod file

func (*Module) Directory

func (m *Module) Directory(subpaths ...string) string

func (*Module) Import

func (m *Module) Import(subpaths ...string) string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL