Documentation
¶
Index ¶
- type Argument
- type BindSet
- func (instance *BindSet) GlobalBind(argumentName string) (string, bool)
- func (instance *BindSet) GlobalBindNames() []string
- func (instance *BindSet) Name(argumentName string, parameterName string) *BindSet
- func (instance *BindSet) Package(importPath string, directory string) *PackageBinding
- func (instance *BindSet) Packages() []*PackageBinding
- type Constructor
- type GenerateCommand
- type GenerateReport
- type GenerateRequest
- type PackageBinding
- func (instance *PackageBinding) Bind(argumentName string) (string, bool)
- func (instance *PackageBinding) BindNames() []string
- func (instance *PackageBinding) Directory() string
- func (instance *PackageBinding) Exclude(pattern string) *PackageBinding
- func (instance *PackageBinding) Excludes() []string
- func (instance *PackageBinding) ImportPath() string
- func (instance *PackageBinding) Name(argumentName string, parameterName string) *PackageBinding
- type ScanResult
- type SkippedConstructor
- type TypeReference
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Argument ¶
type Argument struct {
Name string
Type *TypeReference
IsScalar bool
}
Argument is one constructor parameter. A scalar is filled from a configuration parameter through a bind; anything else is resolved from the container by type.
type BindSet ¶
type BindSet struct {
// contains filtered or unexported fields
}
func NewBindSet ¶
func NewBindSet() *BindSet
BindSet declares how the scalar arguments of the scanned constructors are filled. A constructor argument whose type is not a service — a string, a number, a duration — cannot be resolved from the container, so it is bound by argument name to a configuration parameter, the way an application binds its own settings once instead of threading them through every provider.
A bind declared on a package applies only to the constructors found under it; a bind declared on the set itself applies everywhere. The generator reports a bind that never matched an argument, which is what turns a misspelled name into an error rather than a silently unfilled dependency.
func (*BindSet) GlobalBind ¶
func (*BindSet) GlobalBindNames ¶
func (*BindSet) Name ¶
Name binds an argument name to a configuration parameter across every scanned package.
func (*BindSet) Package ¶
func (instance *BindSet) Package(importPath string, directory string) *PackageBinding
Package declares a package to scan. The import path is the one the generated file imports; the directory is where the sources live, relative to the project directory, and is scanned together with everything below it.
func (*BindSet) Packages ¶
func (instance *BindSet) Packages() []*PackageBinding
type Constructor ¶
type Constructor struct {
Name string
ImportPath string
PackageName string
File string
Line int
ReturnType *TypeReference
/* ServiceNameIdentifier is the exported constant a //melody:service directive names. The generated file references the constant rather than copying its value, so the service name keeps a single definition. Empty registers the service by type alone. */
ServiceNameIdentifier string
ReturnsError bool
Arguments []*Argument
DirectiveBinds map[string]string
}
Constructor is one discovered provider function, described in the terms the generator emits: where it lives, what it returns and what it needs.
type GenerateCommand ¶
type GenerateCommand struct {
// contains filtered or unexported fields
}
func NewGenerateCommand ¶
func NewGenerateCommand(bindSet *BindSet) *GenerateCommand
NewGenerateCommand builds the command that renders the service registrations for a bind set. It runs inside the application, so it checks every bind against the parameters the running configuration actually declares instead of against a copy of them. The output package must not be one the scanned constructors take types from: the generated file would import its own package.
func (*GenerateCommand) Description ¶
func (instance *GenerateCommand) Description() string
func (*GenerateCommand) Flags ¶
func (instance *GenerateCommand) Flags() []clicontract.Flag
func (*GenerateCommand) Name ¶
func (instance *GenerateCommand) Name() string
func (*GenerateCommand) Run ¶
func (instance *GenerateCommand) Run( runtimeInstance runtimecontract.Runtime, commandContext *clicontract.CommandContext, ) error
type GenerateReport ¶
type GenerateReport struct {
ConstructorCount int
Skipped []*SkippedConstructor
UnusedBinds []string
GlobalBindReach map[string][]string
}
func Generate ¶
func Generate(request *GenerateRequest) (string, *GenerateReport, error)
Generate scans every declared package and renders the registration source. It fails on the first constructor whose scalar argument no bind covers: an unfilled scalar has no safe default, and letting it through would move the failure to a runtime far from its cause.
type GenerateRequest ¶
type GenerateRequest struct {
ProjectDirectory string
PackageName string
FunctionName string
BindSet *BindSet
/* DeclaredParameters is the set of parameter names the application declares. When it is empty the generator cannot check a bind target and says so instead of assuming the target exists. */
DeclaredParameters map[string]bool
}
type PackageBinding ¶
type PackageBinding struct {
// contains filtered or unexported fields
}
func (*PackageBinding) Bind ¶
func (instance *PackageBinding) Bind(argumentName string) (string, bool)
func (*PackageBinding) BindNames ¶
func (instance *PackageBinding) BindNames() []string
func (*PackageBinding) Directory ¶
func (instance *PackageBinding) Directory() string
func (*PackageBinding) Exclude ¶
func (instance *PackageBinding) Exclude(pattern string) *PackageBinding
Exclude skips every constructor whose returned type name matches the pattern, in the syntax of path.Match. Test files are always excluded.
func (*PackageBinding) Excludes ¶
func (instance *PackageBinding) Excludes() []string
func (*PackageBinding) ImportPath ¶
func (instance *PackageBinding) ImportPath() string
func (*PackageBinding) Name ¶
func (instance *PackageBinding) Name(argumentName string, parameterName string) *PackageBinding
Name binds an argument name to a configuration parameter for the constructors of this package only, taking precedence over a bind of the same name declared on the set.
type ScanResult ¶
type ScanResult struct {
Constructors []*Constructor
Skipped []*SkippedConstructor
}
ScanResult carries what a scan found together with what it deliberately left out, so the generator can report the skipped constructors instead of silently narrowing its coverage.
func Scan ¶
func Scan(projectDirectory string, packageBinding *PackageBinding) (*ScanResult, error)
Scan walks the directory of a package binding and returns every constructor it can wire. A directory below the one declared is scanned as its own package, its import path derived from the relative path, so a package declared as the root of a domain covers the packages beneath it.