depgraph

package module
v0.0.0-...-e975ef8 Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2023 License: MIT Imports: 9 Imported by: 0

README

DepGraph

PkgGoDev License Go Report Card

DepGraph is a package to figure out an efficient dependency tree for a Go package.

The dependency graph is built by inspecting file imports only, which is faster than go list, or ast parsing.

It can be used to figure out why a particular package is imported into a service.

Documentation

Overview

Package depgraph provides an efficient golang dependency analysis tool for large modules. It builds the graph by inspecting file imports only, which is faster than go list or ast parsing.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Mod

type Mod struct {
	// Path of the module: github.com/luno/reflex
	Path string

	// Dir of the module on local disk.
	Dir string
}

func (Mod) MaybeHasPkg

func (m Mod) MaybeHasPkg(pkg string) bool

MaybeHasPkg returns true if the package name matches the module. It might not actually exist though.

func (Mod) PkgDir

func (m Mod) PkgDir(pkg string) string

PkgDir returns the package directory path on local disk.

type Node

type Node struct {
	// Name is the package path.
	Name string

	// Children are all direct downstream packages this package imports.
	Children []*Node

	// Descendants is union of all downstream packages.
	// Only internal packages (same module) are expanded.
	Descendants map[*Node]bool

	// Parents are direct upstream packages importing this package.
	Parents []*Node

	// Height is depth of deepest internal branch (chain of same module descendants).
	Height int

	// FileImports are the imports per go file (relative to module dir).
	// Only applicable files are included, so _test.go files and mismatching build tags are excluded.
	FileImports map[string][]string
	// contains filtered or unexported fields
}

Node represents a package in a import/dependency graph.

func Make

func Make(mod Mod, tags Tags, inclExt bool, pkgs ...string) ([]*Node, error)

Make returns a dependency graph with the provided packages as root nodes.

Only internal imports (packages of the provided module) are expanded. Only direct external imports (packages of other modules) are included if inclExt is true.

Build tags are respected and _test.go files are excluded.

func (*Node) AddParent

func (n *Node) AddParent(parent *Node)

AddParent adds a parent safely.

type Tags

type Tags map[string]bool

Tags represents golang build tags. The zero value is the default (no build tags).

Jump to

Keyboard shortcuts

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