depgraph

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2025 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package depgraph builds a Zero's dependeny injection type graph.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type API

type API struct {
	// Position is the position of the function declaration.
	Position token.Position
	// Pattern is the parsed HTTP mux pattern
	Pattern *directiveparser.DirectiveAPI
	// Function is the function that handles the API
	Function *types.Func
	// Package is the package that contains the function
	Package *packages.Package
	// Options is a map of options for the API endpoint
	Options map[string]string
}

API represents a method that is an exposed API endpoint. API endpoints are annotated like so:

//zero:api [<method>] [<host>]/[<path>] [<option>[=<value>] ...]

type Graph

type Graph struct {
	Dest      *types.Package
	Providers map[string]*Provider
	Configs   map[string]types.Type
	APIs      []*API
	Missing   map[*types.Func][]types.Type
}

func Analyse

func Analyse(dest string, options ...Option) (*Graph, error)

Analyse statically loads Go packages, then analyses them for //zero:... annotations in order to build the Zero's dependency injection graph.

func (*Graph) Graph

func (g *Graph) Graph() map[string][]string

Graph returns the dependency graph as a map where keys are type strings and values are slices of their dependency type strings.

func (*Graph) ImportAlias

func (g *Graph) ImportAlias(pkg string) string

ImportAlias returns an alias for the given package path, or "" if the package is the destination package.

func (*Graph) TypeString

func (g *Graph) TypeString(t types.Type) (imp, typ string)

TypeString splits a type into its import alias+path and type reference.

eg. *database/sql.DB would become

impc112c3711fba7de3 "database/sql"
*sql.DB

type Option

type Option func(*graphOptions) error

func WithPatterns

func WithPatterns(patterns ...string) Option

WithPatterns adds additional package patterns to search for annotations.

func WithProviders

func WithProviders(pick ...string) Option

WithProviders selects a provider for a type if multiple are available.

func WithRoots

func WithRoots(roots ...string) Option

WithRoots selects a set of root types for the graph.

type Provider

type Provider struct {
	// Position is the position of the function declaration.
	Position  token.Position
	Directive *directiveparser.DirectiveProvider
	// Function is the function that provides the type.
	Function *types.Func
	// Package is the package that contains the function.
	Package  *packages.Package
	Provides types.Type
	Requires []types.Type
}

Jump to

Keyboard shortcuts

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