Documentation
¶
Index ¶
- Constants
- func GetConfig(impl any) any
- func GetImpl[T any](gr getRuntime) (*T, error)
- func GetIntf[T any](gr getRuntime, name string) (T, error)
- func HasConfig(impl any) bool
- func IfaceType[T any]() (reflect.Type, error)
- func MustProvide[Iface any, Impl any](opts ...Option)
- func ParseTOML(input string) (map[string]string, error)
- func Provide[Iface any, Impl any](opts ...Option) error
- func Run[T any, P PointerToSystem[T]](ctx context.Context, config Config, start func(context.Context, *T) error) error
- func StructType[T any]() (reflect.Type, error)
- func Type[T any]() reflect.Type
- func ValidateDeps(deps []*Dep) error
- type Config
- type Dep
- type Implements
- type InstanceOf
- type Option
- type PointerToSystem
- type Ref
- type Runtime
- type System
- type WithConfig
- type WithLog
Constants ¶
const PkgPath = "github.com/cgfork/deps"
Variables ¶
This section is empty.
Functions ¶
func GetConfig ¶
GetConfig returns the config stored in the provided implementation, or returns nil if the implementation does not have a config.
func HasConfig ¶
HasConfig returns true if the provided implementation has an embeded deps.WithConfig field.
func MustProvide ¶
func Run ¶
func Run[T any, P PointerToSystem[T]](ctx context.Context, config Config, start func(context.Context, *T) error) error
Run starts a deps system.
func StructType ¶
StructType returns the reflect.Type for the struct.
func Type ¶
Type returns the reflect.Type for T.
This function is particularly useful when T is an interface and it is impossible to get a value with concrete type T.
func ValidateDeps ¶
ValidateDeps validates the given registrations. It makes sure that every type which is refered by the runtime.Ref field of the impl type has been registered.
Types ¶
type Dep ¶
type Dep struct {
// contains filtered or unexported fields
}
Dep represents the relationship between an interface and its implementation
type Implements ¶
type Implements[T any] struct { // contains filtered or unexported fields }
/ Implements is a struct that can be embedded in an implementation.
type InstanceOf ¶
type InstanceOf[T any] interface { // contains filtered or unexported methods }
InstanceOf[T] is the interface implemented by a struct that embeds deps.Implements[T].
type PointerToSystem ¶
type PointerToSystem[T any] interface { *T // Ensure that the T type embeds Implements[System]. InstanceOf[System] }
PointerToSystem is a type constraint that asserts *T is an instance of System.
type Ref ¶
type Ref[T any] struct { // contains filtered or unexported fields }
Ref[T] is a field that can be placed inside an implementation struct. T must be a registered type. Runtime will automatically wire such a field with a handle to the corresponding implementation.
type Runtime ¶
type Runtime interface { // GetImpl returns the instance of the given type. GetImpl(reflect.Type) (any, error) // GetIntf returns the implementation instance of the given interface Type // with the given name. GetIntf(reflect.Type, string) (any, error) }
Runtime is the interface for the deps runtime which provides the way to resolve the references or implementations.
type System ¶
type System interface { }
System is the interface implemented by a deps system which is started by the `RunSystem` function.
type WithConfig ¶
type WithConfig[T any] struct { // contains filtered or unexported fields }
WithConfig[T] is a type that can be embedded inside a implementation struct. implementation. The runtime will take per-construct configuration information found in the application config file and use it to initialize the contents of T.
func (*WithConfig[T]) Config ¶
func (wc *WithConfig[T]) Config() *T
Config returns the configuration information for the implementation that embeds this deps.WithConfig.
Any fields in T that were not present in the application config file will have their default values.
Any fields in the application config file that are not present in T will be flagged as an error at application startup.