inject

package
v0.0.0-...-3c5bc29 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2021 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Bootstrap

func Bootstrap(baseCtx context.Context, initializers ...Initializer) (Injector, Releaser, error)

Bootstrap calls all initializers and returns a compound Injector and Releaser. In case of error, the Releasers obtained until then are returned to allow for a clean exit.

func InjectorMiddlewareFactory

func InjectorMiddlewareFactory(injector Injector) func(http.Handler) http.Handler

InjectorMiddlewareFactory returns a simple HTTP middleware which populates Context using the injector. Note: this simple implementation panics if Inject returns error.

func MustInitialize

func MustInitialize(ctx context.Context, initializer Initializer) (Injector, Releaser)

MustInitialize calls the Initializer, panicking on error.

func MustInject

func MustInject(ctx context.Context, injector Injector) context.Context

MustInject calls the Injector, panicking on error.

func SafeRelease

func SafeRelease(releaser Releaser)

SafeRelease calls Release on the Releaser if not nil. Note: this is mainly needed because a Releaser can be returned by Bootstrap also in case of error.

Types

type Initializer

type Initializer func(ctx context.Context) (Injector, Releaser, error)

Initializer initializes a value, returning a corresponding Injector and Releaser.

type Injector

type Injector func(ctx context.Context) (context.Context, error)

Injector injects values into a Context.

func CompoundInjectorFactory

func CompoundInjectorFactory(injectors ...Injector) Injector

CompoundInjectorFactory combines multiple injectors into one.

func SingletonInjectorFactory

func SingletonInjectorFactory(contextKey, value interface{}) Injector

SingletonInjectorFactory always injects the given (contextKey, value) pair.

type Releaser

type Releaser func()

Releaser releases an initialized resource.

func CloseReleaserFactory

func CloseReleaserFactory(closer io.Closer) Releaser

CloseReleaserFactory is a releaser that calls Close.

func CompoundReleaserFactory

func CompoundReleaserFactory(releasers ...Releaser) Releaser

CompoundReleaserFactory combines multiple releasers into one (invoking them in reverse order).

Directories

Path Synopsis
injectmocks
Package injectmocks is a generated GoMock package.
Package injectmocks is a generated GoMock package.

Jump to

Keyboard shortcuts

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