Documentation ¶
Overview ¶
Package inject implements delayed binding of function calls to runtime.
Index ¶
- func Add(parent context.Context, name Name, runner Runner) error
- func Assign(src, dst interface{}) error
- func AssignSome(src, dst interface{}) error
- func AssignableTo(src, dst interface{}) error
- func ElementStackTrace() string
- func NewContext(parent context.Context) context.Context
- func RegisterLineMap(goElementPath, anElementPath, elementName string, lineMap map[int]int)
- type CheckedRunner
- type FuncRunner
- type Name
- type NameQuery
- type RunFunc
- type Runner
- type TypedRunner
- type Value
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Assign ¶
func Assign(src, dst interface{}) error
Assign assigns values from Value or struct to Value or struct. If src is not AssignableTo dst, return an error.
func AssignSome ¶
func AssignSome(src, dst interface{}) error
AssignSome assigns some values from Value or struct to Value or struct. Like Assign but ignore fields in src that are not present in dst.
func AssignableTo ¶
func AssignableTo(src, dst interface{}) error
AssignableTo returns if src is assignable to dst. Typing rule is as follows: (1) every field of src must have a field of the same name in dst, (2) the type of the src field must be golang assignable to the dst field, and (3) the dst fields must be golang settable (i.e., have an address).
func ElementStackTrace ¶
func ElementStackTrace() string
ElementStackTrace creates a stack trace, detecting whether or not the panic occured within an element. If the panic did not occur within an element, then the normal debug.Stack() is returned. Otherwise, we use the registered line maps to create a stack trace which refers back to the original elements, with the correct line numbers.
func NewContext ¶
NewContext creates a new inject context
func RegisterLineMap ¶
During code generation of elements, we append to the generated Go code a map that relates line numbers of Go back to the original line numbers of the element.an file. In the init() function of the generated elements, we call in here to RegisterLineMap in order to create a global mapping for every known element. This later allows us to rework panics and provide the original line numbers should a panic of some sort occur within an element.
Types ¶
type CheckedRunner ¶
type CheckedRunner struct { RunFunc In interface{} Out interface{} }
A CheckedRunner is a typed injectable function. It checks if input parameter is assignable to In and output parameter is assignable to Out.
func (*CheckedRunner) Input ¶
func (a *CheckedRunner) Input() interface{}
Input returns an example of an input to this Runner
func (*CheckedRunner) Output ¶
func (a *CheckedRunner) Output() interface{}
Output returns an example of an output of this Runner
type Name ¶
type Name struct { Host string // Host Repo string // Name Tag string // Version Stage api.ElementStage }
Name uniquely identifiers a inject.Runner
type NameQuery ¶
type NameQuery struct { Repo string // Name Tag string // Version Stage api.ElementStage }
NameQuery is a query for a Runner
type Runner ¶
type Runner interface { // Run the function and return results Run(context.Context, Value) (Value, error) }
A Runner is an injectable function
type TypedRunner ¶
type TypedRunner interface { Runner Input() interface{} Output() interface{} }
A TypedRunner is a typed injectable function