kinitx

package
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2021 License: MIT Imports: 6 Imported by: 5

Documentation

Overview

Package kinitx provides the KInit expansion set.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Attach

func Attach(x interface{}) error

Attach calls the Attach method of the global container by passing a processor based on the given entity.

The x argument will be parsed corresponding to following rules:

- x must not be nil;

- if x implements the kinit.Processor interface it will be used by itself;

- otherwise x will be parsed using the NewProcessor.

func Bind

func Bind(i, x interface{}) error

Bind calls the Provide method of the global container bu passing a binder based on given interface and object.

See the documentation for the NewBinder to find out possible values of the argument x.

func Consider

func Consider(x interface{}) error

Consider calls the Require method of the global inspector for each dependency of the functor based on the given entity.

See the documentation for the Run to find out possible values of the argument x.

func Ignore

func Ignore(x interface{}) error

Ignore calls the Ignore method of the global inspector by passing the type of the given entity.

The argument x must not be nil.

func Inspect

func Inspect(opt *kinitq.Options) error

Inspect calls the Inspect method of the global inspector on the global container.

func MustAttach

func MustAttach(x interface{})

MustAttach is a variant of the Attach that panics on error.

func MustBind

func MustBind(i, x interface{})

MustBind is a variant of the Bind that panics on error.

func MustConsider

func MustConsider(x interface{})

MustConsider is a variant of the Consider that panics on error.

func MustIgnore

func MustIgnore(x interface{})

MustIgnore is a variant of the Ignore that panics on error.

func MustInspect

func MustInspect(opt *kinitq.Options)

MustInspect is a variant of the Inspect that panics on error.

func MustProvide

func MustProvide(x interface{})

MustProvide is a variant of the Provide that panics on error.

func MustRequire

func MustRequire(x interface{})

MustRequire is a variant of the Require that panics on error.

func MustRun

func MustRun(xx ...interface{})

MustRun is a variant of the Run that panics on error.

func Provide

func Provide(x interface{}) error

Provide calls the Provide method of the global container by passing a constructor based on the given entity.

The x argument will be parsed corresponding to following rules:

- x must not be nil;

- if x implements the kinit.Constructor interface it will used by itself;

- if x is a function it will be parsed using the NewOpener only when returns an implementation of the io.Closer interface at the first position and, optionally, error at the second; all other functions will be parsed using the NewConstructor;

- if x is a struct or pointer it will be parsed using the NewInitializer;

- all other variants of x are unacceptable.

func Require

func Require(x interface{}) error

Require calls the Require method of the global inspector by passing the type of the given entity.

The argument x must not be nil.

func Run

func Run(xx ...interface{}) error

Run calls the Run method of the global container by passing functors based on given entities.

Items of the xx argument (let's name each item as x) will be parsed corresponding to following rules:

- x must not be nil;

- if x is a function it will be parsed using the NewFunctor;

- otherwise x will be parsed using the NewInjector.

Types

type Binder

type Binder struct {
	// contains filtered or unexported fields
}

Binder represents a pseudo-constructor that casts an object to an interface.

func MustNewBinder

func MustNewBinder(i, x interface{}) *Binder

MustNewBinder is a variant of the NewBinder that panics on error.

func NewBinder

func NewBinder(i, x interface{}) (*Binder, error)

NewBinder returns a new binder.

The argument i must be an interface pointer and the argument x must not be nil.

func (*Binder) Create

func (b *Binder) Create(a ...reflect.Value) (reflect.Value, kdone.Destructor, error)

Create implements the kinit.Constructor interface.

func (*Binder) Parameters

func (b *Binder) Parameters() []reflect.Type

Parameters implements the kinit.Constructor interface.

func (*Binder) Type

func (b *Binder) Type() reflect.Type

Type implements the kinit.Constructor interface.

type Constructor

type Constructor struct {
	// contains filtered or unexported fields
}

Constructor represents a constructor based on a function.

func MustNewConstructor

func MustNewConstructor(x interface{}) *Constructor

MustNewConstructor is a variant of the NewConstructor that panics on error.

func NewConstructor

func NewConstructor(x interface{}) (*Constructor, error)

NewConstructor returns a new constructor.

The argument x must be a function that is compatible with one of following signatures (T is an arbitrary Go type):

func(...) T;

func(...) (T, error);

func(...) (T, kdone.Destructor, error).

func (*Constructor) Create

Create implements the kinit.Constructor interface.

func (*Constructor) Parameters

func (c *Constructor) Parameters() []reflect.Type

Parameters implements the kinit.Constructor interface.

func (*Constructor) Type

func (c *Constructor) Type() reflect.Type

Type implements the kinit.Constructor interface.

type Functor

type Functor struct {
	// contains filtered or unexported fields
}

Functor represents a functor based on a function.

func MustNewFunctor

func MustNewFunctor(x interface{}) *Functor

MustNewFunctor is a variant of the NewFunctor that panics on error.

func NewFunctor

func NewFunctor(x interface{}) (*Functor, error)

NewFunctor returns a new functor.

The argument x must be a function that is compatible with one of following signatures:

func(...)

func(...) error

func(...) (kinit.Functor, error)

func(...) ([]kinit.Functor, error)

func (*Functor) Call

func (f *Functor) Call(a ...reflect.Value) ([]kinit.Functor, error)

Call implements the kinit.Functor interface.

func (*Functor) Parameters

func (f *Functor) Parameters() []reflect.Type

Parameters implements the kinit.Functor interface.

type Initializer

type Initializer struct {
	// contains filtered or unexported fields
}

Initializer represents a constructor based on a struct.

func MustNewInitializer

func MustNewInitializer(x interface{}) *Initializer

MustNewInitializer is a variant of the NewInitializer that panics on error.

func NewInitializer

func NewInitializer(x interface{}) (*Initializer, error)

NewInitializer returns a new initializer.

The argument x must be a struct or a struct pointer.

func (*Initializer) Create

Create implements the kinit.Constructor interface.

func (*Initializer) Parameters

func (i *Initializer) Parameters() []reflect.Type

Parameters implements the kinit.Constructor interface.

func (*Initializer) Type

func (i *Initializer) Type() reflect.Type

Type implements the kinit.Constructor interface.

type Injector

type Injector struct {
	// contains filtered or unexported fields
}

Injector represents a functor that provides an object to use directly instead of it creation.

func MustNewInjector

func MustNewInjector(x interface{}) *Injector

MustNewInjector is a variant of the NewInjector that panics on error.

func NewInjector

func NewInjector(x interface{}) (*Injector, error)

NewInjector returns a new injector.

The argument x must not be nil.

func (*Injector) Call

func (i *Injector) Call(a ...reflect.Value) ([]kinit.Functor, error)

Call implements the kinit.Functor interface.

func (*Injector) Parameters

func (i *Injector) Parameters() []reflect.Type

Parameters implements the kinit.Functor interface.

type Opener

type Opener struct {
	// contains filtered or unexported fields
}

Opener represents a constructor based on a function that creates an implementation of the io.Closer interface.

func MustNewOpener

func MustNewOpener(x interface{}) *Opener

MustNewOpener is a variant of the NewOpener that panics on error.

func NewOpener

func NewOpener(x interface{}) (*Opener, error)

NewOpener returns a new opener.

The argument x must be a function that is compatible with one of following signatures (C is an arbitrary implementation of the io.Closer interface):

func(...) C;

func(...) (C, error);

func (*Opener) Create

func (o *Opener) Create(a ...reflect.Value) (reflect.Value, kdone.Destructor, error)

Create implements the kinit.Constructor interface.

func (*Opener) Parameters

func (o *Opener) Parameters() []reflect.Type

Parameters implements the kinit.Constructor interface.

func (*Opener) Type

func (o *Opener) Type() reflect.Type

Type implements the kinit.Constructor interface.

type Processor

type Processor struct {
	// contains filtered or unexported fields
}

Processor represents a processor based on a function.

func MustNewProcessor

func MustNewProcessor(x interface{}) *Processor

MustNewProcessor is a variant of the NewProcessor that panics on error.

func NewProcessor

func NewProcessor(x interface{}) (*Processor, error)

NewProcessor returns a new processor.

The argument x must be a function that is compatible with one of following signatures (T is an arbitrary Go type):

func(T, ...);

func(T, ...) error.

func (*Processor) Parameters

func (p *Processor) Parameters() []reflect.Type

Parameters implements the kinit.Processor interface.

func (*Processor) Process

func (p *Processor) Process(obj reflect.Value, a ...reflect.Value) error

Process implements the kinit.Processor interface.

func (*Processor) Type

func (p *Processor) Type() reflect.Type

Type implements the kinit.Processor interface.

Jump to

Keyboard shortcuts

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