depgraph

package
v5.7.1 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2026 License: Apache-2.0 Imports: 9 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package depgraph builds the dependency graph of a project's services and walks it in (reverse) dependency order, optionally in parallel.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InDependencyOrder

func InDependencyOrder(ctx context.Context, project *types.Project, fn func(context.Context, string) error, options ...Option) error

InDependencyOrder applies the function to the services of the project taking in account the dependency order

func InReverseDependencyOrder

func InReverseDependencyOrder(ctx context.Context, project *types.Project, fn func(context.Context, string) error, options ...Option) error

InReverseDependencyOrder applies the function to the services of the project in reverse order of dependencies

Types

type Graph

type Graph struct {
	Vertices map[string]*Vertex
	// contains filtered or unexported fields
}

Graph represents project as service dependencies

func NewGraph

func NewGraph(project *types.Project, initialStatus ServiceStatus) (*Graph, error)

NewGraph returns the dependency graph of the services. It never modifies the project: an optional (required: false) dependency on a service absent from the model simply contributes no edge; pruning such references from the model itself is the caller's explicit decision — see Project.WithoutUnresolvedOptionalDependencies.

func (*Graph) AddEdge

func (g *Graph) AddEdge(source string, destination string) error

AddEdge adds a relationship of dependency between vertices `source` and `destination`

func (*Graph) AddVertex

func (g *Graph) AddVertex(key string, serviceName string, initialStatus ServiceStatus)

AddVertex adds a vertex to the Graph

func (*Graph) FilterChildren

func (g *Graph) FilterChildren(key string, status ServiceStatus) []*Vertex

FilterChildren returns children of a certain vertex that are in a certain status

func (*Graph) FilterParents

func (g *Graph) FilterParents(key string, status ServiceStatus) []*Vertex

FilterParents returns the parents of a certain vertex that are in a certain status

func (*Graph) HasCycles

func (g *Graph) HasCycles() (bool, error)

HasCycles detects cycles in the graph

func (*Graph) Leaves

func (g *Graph) Leaves() []*Vertex

Leaves returns the slice of leaves of the graph

func (*Graph) Roots

func (g *Graph) Roots() []*Vertex

Roots returns the slice of "Roots" of the graph

func (*Graph) UpdateStatus

func (g *Graph) UpdateStatus(key string, status ServiceStatus)

UpdateStatus updates the status of a certain vertex

type Option

type Option func(*graphTraversal)

Option customizes a dependency-order traversal.

func WithMaxConcurrency

func WithMaxConcurrency(maxConcurrency int) Option

WithMaxConcurrency bounds the number of services visited concurrently (<=0 means unbounded).

func WithRootNodesAndDown

func WithRootNodesAndDown(nodes []string) Option

WithRootNodesAndDown restricts a reverse-order traversal to the given services and the services depending on them.

type ServiceStatus

type ServiceStatus int

ServiceStatus indicates the status of a service

const (
	ServiceStopped ServiceStatus = iota
	ServiceStarted
)

Services status flags

type Vertex

type Vertex struct {
	Key      string
	Service  string
	Status   ServiceStatus
	Children map[string]*Vertex
	Parents  map[string]*Vertex
}

Vertex represents a service in the dependencies structure

func NewVertex

func NewVertex(key string, serviceName string, initialStatus ServiceStatus) *Vertex

NewVertex is the constructor function for the Vertex

func (*Vertex) GetChildren

func (v *Vertex) GetChildren() []*Vertex

GetChildren returns a slice with the child vertices of the Vertex

func (*Vertex) GetParents

func (v *Vertex) GetParents() []*Vertex

GetParents returns a slice with the parent vertices of the Vertex

Jump to

Keyboard shortcuts

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