imptree

package
v0.0.0-...-947c368 Latest Latest
Warning

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

Go to latest
Published: May 3, 2022 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Copyright 2022 tobbstr. All rights reserved. Use of this source code is governed by a MIT- license that can be found in the LICENSE file.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Builder

type Builder struct {
	// contains filtered or unexported fields
}

Builder is a tree builder. A Builder should not be reused for different trees, instead a new Builder should be instantiated.

func NewBuilder

func NewBuilder() *Builder

NewBuilder constructs an initialized Builder

func (*Builder) Build

func (b *Builder) Build(importPath string, matchPkg MatchPkg) (*Node, error)

Build builds and returns a doubly-linked tree of import paths, so it's possible to see which packages are imported by a package (its children) and also which packages import a package (its parents). The tree's root package is given by importPath. Only packages matched by matchPkg are included in the tree.

Ex.

builder.Build("github.com/johndoe/example/cmd/acme", func(pkg *package.Package) bool{
	// includes only packages belonging to the same module
	if strings.Contains(pkg.PkgPath, "github.com/johndoe/example") {
		return true
	}
	return false
})

type MatchPkg

type MatchPkg func(*packages.Package) bool

MatchPkg is a predicate function for selecting which Go packages to include in the tree

type Node

type Node struct {
	// Children are links to imported packages
	Children []*Node
	// Parents are links to packages that import this package
	Parents []*Node
	// PkgPath is the import path to this package
	PkgPath string
}

Node represents a Go source package

func (*Node) Remove

func (n *Node) Remove(node *Node)

Jump to

Keyboard shortcuts

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