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 Config ¶ added in v0.5.0
type Config struct {
// Position of the type declaration.
Position token.Position
Type types.Type
Directive *directiveparser.DirectiveConfig
}
Config represents command-line/file configuration. Config structs are annotated like so:
//zero:config [prefix="<prefix>"]
type Graph ¶
type Graph struct {
Dest *types.Package
Providers map[string]*Provider
MultiProviders map[string][]*Provider // Multiple providers for multi types
Configs map[string]*Config
APIs []*API
Middleware []*Middleware
Missing map[*types.Func][]types.Type
}
func Analyse ¶
Analyse statically loads Go packages, then analyses them for //zero:... annotations in order to build the Zero's dependency injection graph.
func (*Graph) FunctionRef ¶ added in v0.1.0
FunctionRef returns a reference to a function, including import information if needed.
func (*Graph) GetProviders ¶ added in v0.7.0
GetProviders returns all providers for a given type (both single and multi).
func (*Graph) Graph ¶
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 ¶
ImportAlias returns an alias for the given package path, or "" if the package is the destination package.
type Middleware ¶ added in v0.1.0
type Middleware struct {
// Position is the position of the function declaration.
Position token.Position
// Directive is the parsed middleware directive
Directive *directiveparser.DirectiveMiddleware
// Function is the function that implements the middleware
Function *types.Func
// Package is the package that contains the function
Package *packages.Package
// Requires are the dependencies required by this middleware
Requires []types.Type
// Factory represents whether the middleware is a factory, or direct middleware function
Factory bool
}
Middleware represents a function that is an HTTP middleware. Middleware functions are annotated like so:
//zero:middleware [<label>]
func (*Middleware) Match ¶ added in v0.1.0
func (m *Middleware) Match(api *API) bool
type Option ¶
type Option func(*graphOptions) error
func WithOptions ¶ added in v0.0.2
func WithPatterns ¶
WithPatterns adds additional package patterns to search for annotations.
func WithProviders ¶
WithProviders selects a provider for a type if multiple are available.
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
}