Documentation ¶
Overview ¶
Package kinitx provides the KInit expansion set.
Index ¶
- func Attach(x interface{}) error
- func Bind(i, x interface{}) error
- func Consider(x interface{}) error
- func Ignore(x interface{}) error
- func Inspect(opt *kinitq.Options) error
- func MustAttach(x interface{})
- func MustBind(i, x interface{})
- func MustConsider(x interface{})
- func MustIgnore(x interface{})
- func MustInspect(opt *kinitq.Options)
- func MustProvide(x interface{})
- func MustRequire(x interface{})
- func MustRun(xx ...interface{})
- func Provide(x interface{}) error
- func Require(x interface{}) error
- func Run(xx ...interface{}) error
- type Binder
- type Constructor
- type Functor
- type Initializer
- type Injector
- type Opener
- type Processor
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 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 ¶
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 ¶
NewBinder returns a new binder.
The argument i must be an interface pointer and the argument x must not be nil.
func (*Binder) Parameters ¶
Parameters 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 ¶
func (c *Constructor) Create(a ...reflect.Value) (reflect.Value, kdone.Destructor, error)
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 ¶
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) Parameters ¶
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 ¶
func (i *Initializer) Create(a ...reflect.Value) (reflect.Value, kdone.Destructor, error)
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 (*Injector) Parameters ¶
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 ¶
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) Parameters ¶
Parameters 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 ¶
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 ¶
Parameters implements the kinit.Processor interface.