Documentation ¶
Overview ¶
Package gen is used to conveniently create new ValueFunc or Containers
Markers defined in this package Markers defined in this package are also used by di-check to compute the dependency graph between all declared or used Containers & ValueFunc
Index ¶
Constants ¶
const ( DIMarkerName = "di" ContainerMarkerName = "container" ValueFuncMarkerName = "valuefunc" )
Variables ¶
var ContainerMarkerDefinition = markers.Must( markers.MakeDefinition(markerName(DIMarkerName, ContainerMarkerName), markers.DescribesPackage, Container{}), )
var ValueFuncMarkerDefinition = markers.Must( markers.MakeDefinition(markerName(DIMarkerName, ValueFuncMarkerName), markers.DescribesPackage, ValueFunc{}), )
Functions ¶
This section is empty.
Types ¶
type ContainerGenerator ¶
type ContainerGenerator struct { // HeaderFile specifies the header text (e.g. license) to prepend to generated files. HeaderFile string `marker:",optional"` // Year specifies the year to substitute for " YEAR" in the header file. Year string `marker:",optional"` }
ContainerGenerator Conveniently generates a new Container
Fields:
Name (string) identifies the container to be created.
Exported (optional bool) indicates if the Container should be exported or not. The Container is not exported by default.
func (ContainerGenerator) Generate ¶
func (g ContainerGenerator) Generate(ctx *genall.GenerationContext) error
func (ContainerGenerator) Help ¶
func (ContainerGenerator) Help() *markers.DefinitionHelp
func (ContainerGenerator) RegisterMarkers ¶
func (ContainerGenerator) RegisterMarkers(into *markers.Registry) error
type ValueFunc ¶
type ValueFunc struct { // Name identifies the func that will be used to access the defined value Name string // Container (optional string) specifies the di.Container's Name that will be used to store the Value. // - Container should always resolve to a di.Container defined in the current pkg. // - In other words, the "consumer" of a di.Value, defines both the di.Value and the di.Container in the same // package where the di.Value is consumed. // It's the job of the "producer" of the injectable value to import the ValueFunc from the getter package. // In use cases where an interface is necessary to decouple "consumer" and the "producer", it is a best // practice to create an "interface package" that defines both di.Value & di.Container, which can be imported // by the "consumers" and the "producers" (!! Concurrent producers should NEVER be allowed: greatly reduce the // side effects) Container *string // Type defines the `type` T to the Value[T]. Type string // TypeImport defines package import for the specific type. TypeImport *string // Exported indicates if the ValueFunc should be exported or not. // Container is exported by default. Exported *bool }
ValueFunc describes a single func that is used to conveniently access a di.Value. This marker is also used by the di-checker to create the dependency graph.
type ValueFuncGenerator ¶
type ValueFuncGenerator struct { // HeaderFile specifies the header text (e.g. license) to prepend to generated files. HeaderFile string `marker:",optional"` // Year specifies the year to substitute for " YEAR" in the header file. Year string `marker:",optional"` }
ValueFuncGenerator Creates a single func to conveniently access a di.Value. This marker is also used by the di-checker to create the dependency graph.
Fields:
Name (string) identifies the func that will be used to access the defined value.
Container (optional string) specifies the di.Container's Name that will be used to store the Value. Container should always resolve to a di.Container defined in the current pkg. In other words, the "consumer" of a di.Value, defines both the di.Value and the di.Container in the same package where the di.Value is consumed. It's the job of the "producer" of the injectable value to import the ValueFunc from the getter package. In use cases where an interface is necessary to decouple "consumer" and the "producer", it is a best practice to create an "interface package" that defines both di.Value & di.Container, which can be imported by the "consumers" and the "producers" (!! Concurrent producers should NEVER be allowed: greatly reduce the side effects)
Type (string) defines the type T to the Value[T].
TypeImport (optional string) defines package import for the specific type.
Exported indicates if the ValueFunc should be exported or not. The ValueFunc is exported by default.
func (ValueFuncGenerator) Generate ¶
func (g ValueFuncGenerator) Generate(ctx *genall.GenerationContext) error
func (ValueFuncGenerator) Help ¶
func (ValueFuncGenerator) Help() *markers.DefinitionHelp
func (ValueFuncGenerator) RegisterMarkers ¶
func (ValueFuncGenerator) RegisterMarkers(into *markers.Registry) error