Documentation
¶
Index ¶
- func AddDependency[T any](dm *DependencyManager, depenency Acquirable[T]) (T, error)
- func EnsureType[T any](anyConf any) (T, error)
- type Acquirable
- type ContextHolder
- type DependencyManager
- type Initializable
- type Lifecycle
- type LifecycleConfig
- type Provider
- type Releasable
- type Runnable
- type ServiceConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddDependency ¶
func AddDependency[T any](dm *DependencyManager, depenency Acquirable[T]) (T, error)
Acquires dependency and adds it to the DependencyManager.
func EnsureType ¶
Types ¶
type Acquirable ¶
type Acquirable[T any] interface { // Underlying context is canceled once parent context // was canceled and all users released their value. ContextHolder // Acquires underlying value. Returns error if parent context was canceled. Acquire() (T, error) // Releases underlying value. Releasable }
func NewAcquirable ¶
func NewAcquirable[T any](parent context.Context, getStored func() T) Acquirable[T]
type ContextHolder ¶
type DependencyManager ¶
type DependencyManager struct {
// contains filtered or unexported fields
}
func (*DependencyManager) ReleaseAll ¶
func (dm *DependencyManager) ReleaseAll()
Releases all held dependencies.
type Initializable ¶
type Lifecycle ¶
type Lifecycle struct {
// contains filtered or unexported fields
}
func (*Lifecycle) Initialize ¶
Initializes underlying services. anyConf must be of type LifecycleConfig. Provided ctx and log are used only for managed services; logger for lifecycle is provided via config.
type LifecycleConfig ¶
type LifecycleConfig struct { // Logger, used by lifecycle itself. If not set, mocked by dummy logger. Logger logr.Logger // List of services, managed by lifecycle. Services []ServiceConfig }
type Provider ¶
type Provider[T any] interface { Runnable Acquirable[T] }
type Releasable ¶
type Releasable interface {
Release()
}
type Runnable ¶
type Runnable interface { // Runnable is always initialized exactly once before being started. // In initialization phaze not all services might be available yet, so it's // not allowed to acquire any dependencies at this point. Any dependencies // must be acquired at the beginning of call to Run(). Initializable // Runs the service. If it depends on any other services, it must acquire them // right after call to Run(), just before running. If any fatal error occures // during this process initialization, returns it; otherwise blocks until service // is stopped and returns nil. Run() error }
type ServiceConfig ¶
Click to show internal directories.
Click to hide internal directories.