Documentation
¶
Overview ¶
Package depth provides the ability to traverse and retrieve Go source code dependencies in the form of internal and external packages.
For example, the dependencies of the stdlib `strings` package can be resolved like so:
import "github.com/KyleBanks/depth"
var t depth.Tree
err := t.Resolve("strings")
if err != nil {
log.Fatal(err)
}
// Output: "strings has 4 dependencies."
log.Printf("%v has %v dependencies.", t.Root.Name, len(t.Root.Deps))
For additional customization, simply set the appropriate flags on the `Tree` before resolving:
import "github.com/KyleBanks/depth"
t := depth.Tree {
ResolveInternal: true,
ResolveTest: true,
MaxDepth: 10,
}
err := t.Resolve("strings")
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ErrRootPkgNotResolved = errors.New("unable to resolve root package")
ErrRootPkgNotResolved is returned when the root Pkg of the Tree cannot be resolved, typically because it does not exist.
Functions ¶
This section is empty.
Types ¶
type Importer ¶
type Importer interface {
Import(name, srcDir string, im build.ImportMode) (*build.Package, error)
}
Importer defines a type that can import a package and return its details.
type Pkg ¶
type Pkg struct {
Name string `json:"name"`
SrcDir string `json:"-"`
Internal bool `json:"-"`
Resolved bool `json:"resolved"`
Tree *Tree `json:"-"`
Parent *Pkg `json:"-"`
Deps []Pkg `json:"deps"`
}
Pkg represents a Go source package, and its dependencies.
Click to show internal directories.
Click to hide internal directories.