inject

package
v0.0.0-...-040724e Latest Latest
Warning

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

Go to latest
Published: Jun 6, 2019 License: BSD-3-Clause, GPL-2.0 Imports: 9 Imported by: 4

Documentation

Overview

Package inject implements delayed binding of function calls to runtime.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Add

func Add(parent context.Context, name Name, runner Runner) error

Add a function to the inject context

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

func NewContext(parent context.Context) context.Context

NewContext creates a new inject context

func RegisterLineMap

func RegisterLineMap(goElementPath, anElementPath, elementName string, lineMap map[int]int)

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

func (*CheckedRunner) Run

func (a *CheckedRunner) Run(ctx context.Context, value Value) (Value, error)

Run implements a Runner

type FuncRunner

type FuncRunner struct {
	RunFunc
}

A FuncRunner is an untyped injectable function

func (*FuncRunner) Run

func (a *FuncRunner) Run(ctx context.Context, value Value) (Value, error)

Run implements a 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 RunFunc

type RunFunc func(context.Context, Value) (Value, error)

RunFunc is the signature of injectable functions

type Runner

type Runner interface {
	// Run the function and return results
	Run(context.Context, Value) (Value, error)
}

A Runner is an injectable function

func Find

func Find(parent context.Context, query NameQuery) (Runner, error)

Find returns a Runner given a query

type TypedRunner

type TypedRunner interface {
	Runner
	Input() interface{}
	Output() interface{}
}

A TypedRunner is a typed injectable function

type Value

type Value map[string]interface{}

A Value is an input or output of injectable functions. It models named and typed function parameters.

func Call

func Call(parent context.Context, query NameQuery, value Value) (Value, error)

Call a function that satisfies the query

func MakeValue

func MakeValue(x interface{}) Value

MakeValue makes a value from an object

func (Value) Concat

func (a Value) Concat(b Value) (Value, error)

Concat concatenates the fields of one value with another. Returns an error if one value shares the same fields as another.

Jump to

Keyboard shortcuts

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