gen

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2023 License: Apache-2.0 Imports: 11 Imported by: 0

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

View Source
const (
	DIMarkerName        = "di"
	ContainerMarkerName = "container"
	ValueFuncMarkerName = "valuefunc"
)

Variables

Functions

This section is empty.

Types

type Container

type Container struct {
	// Name identifies the container to be created
	Name string
	// Exported indicates if the Container should be exported or not.
	// The Container is not exported by default.
	Exported *bool
}

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 (ContainerGenerator) Help

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 (ValueFuncGenerator) Help

func (ValueFuncGenerator) RegisterMarkers

func (ValueFuncGenerator) RegisterMarkers(into *markers.Registry) error

Jump to

Keyboard shortcuts

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