Documentation
¶
Index ¶
- Constants
- func WithAppInfo(info interfaces.AppInfo) options.Option
- func WithComponentFactory(name string, factory ComponentFactory) options.Option
- func WithContainer(container Container) options.Option
- func WithDefaultCacheName(name string) options.Option
- func WithDefaultDatabaseName(name string) options.Option
- func WithDefaultObjectStoreName(name string) options.Option
- func WithDefaultRegistrarName(name string) options.Option
- func WithLogger(logger log.Logger) options.Option
- type CacheProvider
- type ClientMiddlewareProvider
- type ComponentFactory
- type ComponentFunc
- type Container
- type DatabaseProvider
- type MiddlewareProvider
- type ObjectStoreProvider
- type RegistryProvider
- type ServerMiddlewareProvider
Constants ¶
const DefaultComponentPriority = 1000
DefaultComponentPriority defines the default priority for components. Components with lower priority values are initialized first. It is recommended to use values in increments of 100 to leave space for future adjustments.
Variables ¶
This section is empty.
Functions ¶
func WithAppInfo ¶
func WithAppInfo(info interfaces.AppInfo) options.Option
WithAppInfo sets the application's metadata for the container.
func WithComponentFactory ¶
func WithComponentFactory(name string, factory ComponentFactory) options.Option
WithComponentFactory registers a component factory with the container.
func WithContainer ¶
func WithDefaultCacheName ¶
WithDefaultCacheName sets the global default cache name.
func WithDefaultDatabaseName ¶
WithDefaultDatabaseName sets the global default database name.
func WithDefaultObjectStoreName ¶
WithDefaultObjectStoreName sets the global default object store name.
func WithDefaultRegistrarName ¶
WithDefaultRegistrarName sets the global default registrar name.
Types ¶
type CacheProvider ¶
type CacheProvider interface {
Caches() (map[string]storage.Cache, error)
Cache(name string) (storage.Cache, error)
DefaultCache(globalDefaultName string) (storage.Cache, error)
RegisterCache(name string, cache storage.Cache)
}
CacheProvider provides access to Cache components.
type ClientMiddlewareProvider ¶
type ClientMiddlewareProvider interface {
Names() []string
ClientMiddlewares() (map[string]middleware.KMiddleware, error)
ClientMiddleware(name string) (middleware.KMiddleware, error)
RegisterClientMiddleware(name string, mw middleware.KMiddleware)
}
ClientMiddlewareProvider provides access to client-side middleware components.
type ComponentFactory ¶
type ComponentFactory interface {
// Priority determines the initialization order of the component.
// Components with lower priority values are created and initialized first.
Priority() int
// NewComponent creates a new component instance.
// It receives a component-specific configuration and the container instance,
// allowing it to register other components or access other services.
NewComponent(cfg interfaces.StructuredConfig, container Container, opts ...options.Option) (interfaces.Component, error)
}
ComponentFactory defines the interface for creating generic components. It includes a priority system to manage initialization order.
type ComponentFunc ¶
type ComponentFunc func(cfg interfaces.StructuredConfig, container Container, opts ...options.Option) (interfaces.Component, error)
ComponentFunc is an adapter to allow the use of ordinary functions as ComponentFactory.
func (ComponentFunc) NewComponent ¶
func (c ComponentFunc) NewComponent(cfg interfaces.StructuredConfig, container Container, opts ...options.Option) (interfaces.Component, error)
NewComponent calls the wrapped function.
func (ComponentFunc) Priority ¶
func (c ComponentFunc) Priority() int
Priority returns the default priority for a ComponentFunc. This ensures that function-based components have a predictable, lower priority.
type Container ¶
type Container interface {
Registry(opts ...options.Option) (RegistryProvider, error)
Middleware(opts ...options.Option) (MiddlewareProvider, error)
Cache(opts ...options.Option) (CacheProvider, error)
Database(opts ...options.Option) (DatabaseProvider, error)
ObjectStore(opts ...options.Option) (ObjectStoreProvider, error)
Component(name string, opts ...options.Option) (interfaces.Component, error)
RegisterComponent(name string, comp interfaces.Component)
RegisterFactory(name string, factory ComponentFactory)
HasComponent(name string) bool
RegisteredComponents() []string
Logger() runtimelog.Logger
AppInfo() interfaces.AppInfo
DefaultCache() (storageiface.Cache, error)
DefaultDatabase() (storageiface.Database, error)
DefaultObjectStore() (storageiface.ObjectStore, error)
DefaultRegistrar() (runtimeregistry.KRegistrar, error)
}
Container defines the interface for accessing various runtime components.
func FromOptions ¶
func New ¶
func New(config interfaces.StructuredConfig, opts ...options.Option) Container
New creates a new, concurrency-safe Container instance.
type DatabaseProvider ¶
type DatabaseProvider interface {
Databases() (map[string]storage.Database, error)
Database(name string) (storage.Database, error)
DefaultDatabase(globalDefaultName string) (storage.Database, error)
RegisterDatabase(name string, db storage.Database)
}
DatabaseProvider provides access to Database components.
type MiddlewareProvider ¶
type MiddlewareProvider interface {
Names() []string
ServerMiddlewareProvider
ClientMiddlewareProvider
}
MiddlewareProvider provides access to both server and client middleware components.
type ObjectStoreProvider ¶
type ObjectStoreProvider interface {
ObjectStores() (map[string]storage.ObjectStore, error)
ObjectStore(name string) (storage.ObjectStore, error)
DefaultObjectStore(globalDefaultName string) (storage.ObjectStore, error)
RegisterObjectStore(name string, store storage.ObjectStore)
}
ObjectStoreProvider provides access to ObjectStore components.
type RegistryProvider ¶
type RegistryProvider interface {
Discoveries() (map[string]registry.KDiscovery, error)
Discovery(name string) (registry.KDiscovery, error)
Registrars() (map[string]registry.KRegistrar, error)
Registrar(name string) (registry.KRegistrar, error)
DefaultRegistrar(globalDefaultName string) (registry.KRegistrar, error)
RegisterDiscovery(name string, discovery registry.KDiscovery)
RegisterRegistrar(name string, registrar registry.KRegistrar)
}
RegistryProvider provides access to Discovery and Registrar components. The provider is responsible for creating and managing the lifecycle of these components.
type ServerMiddlewareProvider ¶
type ServerMiddlewareProvider interface {
Names() []string
ServerMiddlewares() (map[string]middleware.KMiddleware, error)
ServerMiddleware(name string) (middleware.KMiddleware, error)
RegisterServerMiddleware(name string, mw middleware.KMiddleware)
}
ServerMiddlewareProvider provides access to server-side middleware components.