Documentation
¶
Index ¶
- Variables
- func GenerateSampleConfig(cfg interface{}, format string) ([]byte, error)
- func LoadTenantConfigs(app Application, tenantService TenantService, params TenantConfigParams) error
- func ProcessConfigDefaults(cfg interface{}) error
- func SaveSampleConfig(cfg interface{}, format, filePath string) error
- func ValidateConfig(cfg interface{}) error
- func ValidateConfigRequired(cfg interface{}) error
- type AppRegistry
- type Application
- type ComplexFeeder
- type Config
- type ConfigProvider
- type ConfigSetup
- type ConfigValidator
- type Configurable
- type Constructable
- type DependencyAware
- type Feeder
- type FileBasedTenantConfigLoader
- type LoadAppConfigFunc
- type Logger
- type Module
- type ModuleConstructor
- type ModuleRegistry
- type ModuleWithConstructor
- type ServiceAware
- type ServiceDependency
- type ServiceProvider
- type ServiceRegistry
- type StandardTenantService
- func (ts *StandardTenantService) GetTenantConfig(tenantID TenantID, section string) (ConfigProvider, error)
- func (ts *StandardTenantService) GetTenants() []TenantID
- func (ts *StandardTenantService) RegisterTenant(tenantID TenantID, configs map[string]ConfigProvider) error
- func (ts *StandardTenantService) RegisterTenantAwareModule(module TenantAwareModule) error
- func (ts *StandardTenantService) RegisterTenantConfigSection(tenantID TenantID, section string, provider ConfigProvider) error
- func (ts *StandardTenantService) RemoveTenant(tenantID TenantID) error
- type Startable
- type StdApplication
- func (app *StdApplication) ConfigProvider() ConfigProvider
- func (app *StdApplication) ConfigSections() map[string]ConfigProvider
- func (app *StdApplication) GetConfigSection(section string) (ConfigProvider, error)
- func (app *StdApplication) GetService(name string, target any) error
- func (app *StdApplication) GetTenantConfig(tenantID TenantID, section string) (ConfigProvider, error)
- func (app *StdApplication) GetTenantService() (TenantService, error)
- func (app *StdApplication) Init() error
- func (app *StdApplication) Logger() Logger
- func (app *StdApplication) RegisterConfigSection(section string, cp ConfigProvider)
- func (app *StdApplication) RegisterModule(module Module)
- func (app *StdApplication) RegisterService(name string, service any) error
- func (app *StdApplication) Run() error
- func (app *StdApplication) Start() error
- func (app *StdApplication) Stop() error
- func (app *StdApplication) SvcRegistry() ServiceRegistry
- func (app *StdApplication) WithTenant(tenantID TenantID) (*TenantContext, error)
- type StdConfigProvider
- type Stoppable
- type TenantApplication
- type TenantAwareConfig
- type TenantAwareModule
- type TenantAwareRegistry
- type TenantConfigLoader
- type TenantConfigParams
- type TenantConfigProvider
- func (tcp *TenantConfigProvider) GetConfig() any
- func (tcp *TenantConfigProvider) GetDefaultConfig() ConfigProvider
- func (tcp *TenantConfigProvider) GetTenantConfig(tenantID TenantID, section string) (ConfigProvider, error)
- func (tcp *TenantConfigProvider) HasTenantConfig(tenantID TenantID, section string) bool
- func (tcp *TenantConfigProvider) SetTenantConfig(tenantID TenantID, section string, provider ConfigProvider)
- type TenantContext
- type TenantID
- type TenantService
Constants ¶
This section is empty.
Variables ¶
var ( // Configuration errors ErrConfigSectionNotFound = errors.New("config section not found") ErrConfigFeederError = errors.New("config: feeder error") ErrConfigSetupError = errors.New("config: setup error") ErrConfigNilPointer = errors.New("cannot create temp config: config pointer is nil") ErrConfigNil = errors.New("cannot create temp config: config is nil") ErrApplicationNil = errors.New("application is nil") ErrConfigProviderNil = errors.New("failed to load app config: config provider is nil") ErrConfigSectionError = errors.New("failed to load app config: error triggered by section") // Config validation errors ErrConfigNotPointer = errors.New("config must be a non-nil pointer") ErrConfigNotStruct = errors.New("config must be a struct") ErrConfigRequiredFieldMissing = errors.New("required field(s) missing in config") ErrConfigValidationFailed = errors.New("configuration validation failed") ErrConfigInvalidFormat = errors.New("invalid configuration format") ErrDefaultValueOverflowsInt = errors.New("default integer value overflows field type") ErrDefaultValueOverflowsUint = errors.New("default unsigned integer value overflows field type") ErrDefaultValueOverflowsFloat = errors.New("default float value overflows field type") ErrUnsupportedTypeForDefault = errors.New("unsupported type for default value") ErrUnsupportedFormatType = errors.New("unsupported format type") // Field kind errors ErrInvalidFieldKind = errors.New("invalid field kind") ErrIncompatibleFieldKind = errors.New("incompatible field kind") ErrUnexpectedFieldKind = errors.New("unexpected field kind") // Service registry errors ErrServiceAlreadyRegistered = errors.New("service already registered") ErrServiceNotFound = errors.New("service not found") // Service injection errors ErrTargetNotPointer = errors.New("target must be a non-nil pointer") ErrTargetValueInvalid = errors.New("target value is invalid") ErrServiceIncompatible = errors.New("service cannot be assigned to target") ErrServiceNil = errors.New("service is nil") ErrServiceWrongType = errors.New("service doesn't satisfy required type") ErrServiceWrongInterface = errors.New("service doesn't satisfy required interface") // Dependency resolution errors ErrCircularDependency = errors.New("circular dependency detected") ErrModuleDependencyMissing = errors.New("module depends on non-existent module") ErrRequiredServiceNotFound = errors.New("required service not found for module") // Tenant errors ErrAppContextNotInitialized = errors.New("application context not initialized") ErrTenantNotFound = errors.New("tenant not found") ErrTenantConfigNotFound = errors.New("tenant config section not found") ErrTenantConfigProviderNil = errors.New("tenant config provider is nil") ErrTenantConfigValueNil = errors.New("tenant config value is nil") ErrTenantRegisterNilConfig = errors.New("cannot register nil config for tenant") ErrMockTenantConfigsNotInitialized = errors.New("mock tenant configs not initialized") ErrConfigSectionNotFoundForTenant = errors.New("config section not found for tenant") // Test-specific errors ErrSetupFailed = errors.New("setup error") ErrFeedFailed = errors.New("feed error") ErrFeedKeyFailed = errors.New("feedKey error") // Tenant config errors ErrConfigCastFailed = errors.New("failed to cast config to expected type") ErrOriginalOrLoadedNil = errors.New("original or loaded config is nil") ErrDestinationNotPointer = errors.New("destination must be a pointer") ErrCannotCopyMapToStruct = errors.New("cannot copy from map to non-struct") ErrUnsupportedSourceType = errors.New("unsupported source type") // Additional tenant config errors ErrTenantSectionConfigNil = errors.New("tenant section config is nil after feeding") ErrCreatedNilProvider = errors.New("created nil provider for tenant section") ErrIncompatibleFieldTypes = errors.New("incompatible types for field assignment") ErrIncompatibleInterfaceValue = errors.New("incompatible interface value for field") )
Application errors
var ConfigFeeders = []Feeder{ feeders.EnvFeeder{}, }
Functions ¶
func GenerateSampleConfig ¶ added in v1.2.2
GenerateSampleConfig generates a sample configuration for a config struct The format parameter can be "yaml", "json", or "toml"
func LoadTenantConfigs ¶ added in v1.1.0
func LoadTenantConfigs(app Application, tenantService TenantService, params TenantConfigParams) error
LoadTenantConfigs scans the given directory for config files. Each file should be named with the tenant ID (e.g. "tenant123.json"). For each file, it unmarshals the configuration and registers it with the provided TenantService for the given section. The configNameRegex is a regex pattern for the config file names (e.g. "^tenant[0-9]+\\.json$").
func ProcessConfigDefaults ¶ added in v1.2.2
func ProcessConfigDefaults(cfg interface{}) error
ProcessConfigDefaults applies default values to a config struct based on struct tags It looks for `default:"value"` tags on struct fields and sets the field value if currently zero/empty
func SaveSampleConfig ¶ added in v1.2.2
SaveSampleConfig generates and saves a sample configuration file
func ValidateConfig ¶ added in v1.2.2
func ValidateConfig(cfg interface{}) error
ValidateConfig validates a configuration using the following steps: 1. Processes default values 2. Validates required fields 3. If the config implements ConfigValidator, calls its Validate method
func ValidateConfigRequired ¶ added in v1.2.2
func ValidateConfigRequired(cfg interface{}) error
ValidateConfigRequired checks all struct fields with `required:"true"` tag and verifies they are not zero/empty values
Types ¶
type AppRegistry ¶
type AppRegistry interface {
SvcRegistry() ServiceRegistry
}
type Application ¶
type Application interface {
ConfigProvider() ConfigProvider
SvcRegistry() ServiceRegistry
RegisterModule(module Module)
RegisterConfigSection(section string, cp ConfigProvider)
ConfigSections() map[string]ConfigProvider
GetConfigSection(section string) (ConfigProvider, error)
RegisterService(name string, service any) error
GetService(name string, target any) error
Init() error
Start() error
Stop() error
Run() error
Logger() Logger
}
func NewStdApplication ¶ added in v1.1.0
func NewStdApplication(cp ConfigProvider, logger Logger) Application
NewStdApplication creates a new application instance
type ComplexFeeder ¶
type Config ¶
func (*Config) AddStructKey ¶
type ConfigProvider ¶
type ConfigProvider interface {
GetConfig() any
}
type ConfigSetup ¶ added in v1.0.0
type ConfigSetup interface {
Setup() error
}
ConfigSetup is an interface that configs can implement to perform additional setup after being populated by feeders
type ConfigValidator ¶ added in v1.2.2
type ConfigValidator interface {
// Validate validates the configuration and returns an error if invalid
Validate() error
}
ConfigValidator is an interface for configuration validation
type Configurable ¶ added in v1.2.0
type Configurable interface {
// RegisterConfig registers configuration requirements
RegisterConfig(app Application) error
}
Configurable is an interface for modules that can have configuration
type Constructable ¶ added in v1.2.0
type Constructable interface {
// Constructor returns a function to construct this module
Constructor() ModuleConstructor
}
Constructable is an interface for modules that can be constructed with a constructor
type DependencyAware ¶ added in v1.2.0
type DependencyAware interface {
// Dependencies returns names of other modules this module depends on
Dependencies() []string
}
DependencyAware is an interface for modules that can have dependencies
type FileBasedTenantConfigLoader ¶ added in v1.1.0
type FileBasedTenantConfigLoader struct {
// contains filtered or unexported fields
}
FileBasedTenantConfigLoader implements TenantConfigLoader for file-based tenant configurations
func DefaultTenantConfigLoader ¶ added in v1.1.0
func DefaultTenantConfigLoader(configDir string) *FileBasedTenantConfigLoader
DefaultTenantConfigLoader creates a loader with default configuration
func NewFileBasedTenantConfigLoader ¶ added in v1.1.0
func NewFileBasedTenantConfigLoader(params TenantConfigParams) *FileBasedTenantConfigLoader
NewFileBasedTenantConfigLoader creates a new file-based tenant config loader
func (*FileBasedTenantConfigLoader) LoadTenantConfigurations ¶ added in v1.1.0
func (l *FileBasedTenantConfigLoader) LoadTenantConfigurations(app Application, tenantService TenantService) error
LoadTenantConfigurations loads tenant configurations from files
type LoadAppConfigFunc ¶ added in v1.0.0
type LoadAppConfigFunc func(*StdApplication) error
LoadAppConfigFunc is the function type for loading application configuration
var AppConfigLoader LoadAppConfigFunc = loadAppConfig
AppConfigLoader is the default implementation that can be replaced in tests
type Module ¶
type Module interface {
// Name returns the unique identifier for this module
Name() string
// Init Initialize the module with the application context
Init(app Application) error
}
Module represents a registrable component in the application
type ModuleConstructor ¶
type ModuleConstructor func(app Application, services map[string]any) (Module, error)
type ModuleRegistry ¶
ModuleRegistry represents a svcRegistry of modules
type ModuleWithConstructor ¶
type ModuleWithConstructor interface {
Module
Constructable
}
type ServiceAware ¶ added in v1.2.0
type ServiceAware interface {
// ProvidesServices returns a list of services provided by this module
ProvidesServices() []ServiceProvider
// RequiresServices returns a list of services required by this module
RequiresServices() []ServiceDependency
}
ServiceAware is an interface for modules that can provide or require services
type ServiceDependency ¶
type ServiceDependency struct {
Name string // Service name to lookup (can be empty for interface-based lookup)
Required bool // If true, application fails to start if service is missing
Type reflect.Type // Concrete type (if known)
SatisfiesInterface reflect.Type // Interface type (if known)
MatchByInterface bool // If true, find first service that satisfies interface type
}
ServiceDependency defines a dependency on a service
type ServiceProvider ¶ added in v1.0.0
ServiceProvider defines a service with metadata
type ServiceRegistry ¶
ServiceRegistry allows registration and retrieval of services
type StandardTenantService ¶ added in v1.1.0
type StandardTenantService struct {
// contains filtered or unexported fields
}
StandardTenantService provides a basic implementation of the TenantService interface
func NewStandardTenantService ¶ added in v1.1.0
func NewStandardTenantService(logger Logger) *StandardTenantService
NewStandardTenantService creates a new tenant service
func (*StandardTenantService) GetTenantConfig ¶ added in v1.1.0
func (ts *StandardTenantService) GetTenantConfig(tenantID TenantID, section string) (ConfigProvider, error)
GetTenantConfig retrieves tenant-specific configuration
func (*StandardTenantService) GetTenants ¶ added in v1.1.0
func (ts *StandardTenantService) GetTenants() []TenantID
GetTenants returns all registered tenant IDs
func (*StandardTenantService) RegisterTenant ¶ added in v1.1.0
func (ts *StandardTenantService) RegisterTenant(tenantID TenantID, configs map[string]ConfigProvider) error
RegisterTenant registers a new tenant with optional initial configs
func (*StandardTenantService) RegisterTenantAwareModule ¶ added in v1.1.0
func (ts *StandardTenantService) RegisterTenantAwareModule(module TenantAwareModule) error
RegisterTenantAwareModule registers a module to receive tenant events
func (*StandardTenantService) RegisterTenantConfigSection ¶ added in v1.1.0
func (ts *StandardTenantService) RegisterTenantConfigSection(tenantID TenantID, section string, provider ConfigProvider) error
RegisterTenantConfigSection registers a configuration section for a specific tenant
func (*StandardTenantService) RemoveTenant ¶ added in v1.1.0
func (ts *StandardTenantService) RemoveTenant(tenantID TenantID) error
RemoveTenant removes a tenant and its configurations
type StdApplication ¶ added in v1.1.0
type StdApplication struct {
// contains filtered or unexported fields
}
StdApplication represents the core StdApplication container
func (*StdApplication) ConfigProvider ¶ added in v1.1.0
func (app *StdApplication) ConfigProvider() ConfigProvider
ConfigProvider retrieves the application config provider
func (*StdApplication) ConfigSections ¶ added in v1.1.0
func (app *StdApplication) ConfigSections() map[string]ConfigProvider
ConfigSections retrieves all registered configuration sections
func (*StdApplication) GetConfigSection ¶ added in v1.1.0
func (app *StdApplication) GetConfigSection(section string) (ConfigProvider, error)
GetConfigSection retrieves a configuration section
func (*StdApplication) GetService ¶ added in v1.1.0
func (app *StdApplication) GetService(name string, target any) error
GetService retrieves a service with type assertion
func (*StdApplication) GetTenantConfig ¶ added in v1.1.0
func (app *StdApplication) GetTenantConfig(tenantID TenantID, section string) (ConfigProvider, error)
GetTenantConfig retrieves configuration for a specific tenant and section
func (*StdApplication) GetTenantService ¶ added in v1.1.0
func (app *StdApplication) GetTenantService() (TenantService, error)
GetTenantService returns the application's tenant service if available
func (*StdApplication) Init ¶ added in v1.1.0
func (app *StdApplication) Init() error
Init initializes the application with the provided modules
func (*StdApplication) Logger ¶ added in v1.1.0
func (app *StdApplication) Logger() Logger
Logger represents a logger
func (*StdApplication) RegisterConfigSection ¶ added in v1.1.0
func (app *StdApplication) RegisterConfigSection(section string, cp ConfigProvider)
RegisterConfigSection registers a configuration section with the application
func (*StdApplication) RegisterModule ¶ added in v1.1.0
func (app *StdApplication) RegisterModule(module Module)
RegisterModule adds a module to the application
func (*StdApplication) RegisterService ¶ added in v1.1.0
func (app *StdApplication) RegisterService(name string, service any) error
RegisterService adds a service with type checking
func (*StdApplication) Run ¶ added in v1.1.0
func (app *StdApplication) Run() error
Run starts the application and blocks until termination
func (*StdApplication) Start ¶ added in v1.1.0
func (app *StdApplication) Start() error
Start starts the application
func (*StdApplication) Stop ¶ added in v1.1.0
func (app *StdApplication) Stop() error
Stop stops the application
func (*StdApplication) SvcRegistry ¶ added in v1.1.0
func (app *StdApplication) SvcRegistry() ServiceRegistry
SvcRegistry retrieves the service svcRegistry
func (*StdApplication) WithTenant ¶ added in v1.1.0
func (app *StdApplication) WithTenant(tenantID TenantID) (*TenantContext, error)
WithTenant creates a tenant context from the application context
type StdConfigProvider ¶
type StdConfigProvider struct {
// contains filtered or unexported fields
}
func NewStdConfigProvider ¶
func NewStdConfigProvider(cfg any) *StdConfigProvider
func (*StdConfigProvider) GetConfig ¶
func (s *StdConfigProvider) GetConfig() any
type TenantApplication ¶ added in v1.1.0
type TenantApplication interface {
Application
GetTenantService() (TenantService, error)
WithTenant(tenantID TenantID) (*TenantContext, error)
GetTenantConfig(tenantID TenantID, section string) (ConfigProvider, error)
}
type TenantAwareConfig ¶ added in v1.1.0
type TenantAwareConfig struct {
// contains filtered or unexported fields
}
TenantAwareConfig provides configuration that's aware of tenant context
func NewTenantAwareConfig ¶ added in v1.1.0
func NewTenantAwareConfig(defaultConfig ConfigProvider, tenantService TenantService, configSection string) *TenantAwareConfig
NewTenantAwareConfig creates a new tenant-aware configuration provider
func (*TenantAwareConfig) GetConfig ¶ added in v1.1.0
func (tac *TenantAwareConfig) GetConfig() any
GetConfig retrieves the default configuration when no tenant is specified
func (*TenantAwareConfig) GetConfigWithContext ¶ added in v1.1.0
func (tac *TenantAwareConfig) GetConfigWithContext(ctx context.Context) any
GetConfigWithContext retrieves tenant-specific configuration based on context
type TenantAwareModule ¶ added in v1.1.0
type TenantAwareModule interface {
Module
// OnTenantRegistered is called when a new tenant is registered
OnTenantRegistered(tenantID TenantID)
// OnTenantRemoved is called when a tenant is removed
OnTenantRemoved(tenantID TenantID)
}
TenantAwareModule is an optional interface that modules can implement to receive notifications about tenant lifecycle events
type TenantAwareRegistry ¶ added in v1.1.0
type TenantAwareRegistry interface {
// GetServiceForTenant returns a service instance for a specific tenant
GetServiceForTenant(name string, tenantID TenantID, target any) error
}
TenantAwareRegistry provides common service discovery methods that are tenant-aware
type TenantConfigLoader ¶ added in v1.1.0
type TenantConfigLoader interface {
// LoadTenantConfigurations loads configurations for all tenants
LoadTenantConfigurations(app Application, tenantService TenantService) error
}
TenantConfigLoader is an interface for loading tenant configurations
type TenantConfigParams ¶ added in v1.1.0
type TenantConfigParams struct {
// ConfigNameRegex is a regex pattern for the config file names (e.g. "^tenant[0-9]+\\.json$").
ConfigNameRegex *regexp.Regexp
// ConfigDir is the directory where tenant config files are located.
ConfigDir string
// ConfigFeeders are the feeders to use for loading tenant configs.
ConfigFeeders []Feeder
}
type TenantConfigProvider ¶ added in v1.1.0
type TenantConfigProvider struct {
// contains filtered or unexported fields
}
TenantConfigProvider manages configurations for multiple tenants
func NewTenantConfigProvider ¶ added in v1.1.0
func NewTenantConfigProvider(defaultConfig ConfigProvider) *TenantConfigProvider
NewTenantConfigProvider creates a new tenant configuration provider
func (*TenantConfigProvider) GetConfig ¶ added in v1.1.0
func (tcp *TenantConfigProvider) GetConfig() any
GetConfig returns the default configuration to satisfy ConfigProvider interface
func (*TenantConfigProvider) GetDefaultConfig ¶ added in v1.1.0
func (tcp *TenantConfigProvider) GetDefaultConfig() ConfigProvider
GetDefaultConfig returns the default configuration (non-tenant specific)
func (*TenantConfigProvider) GetTenantConfig ¶ added in v1.1.0
func (tcp *TenantConfigProvider) GetTenantConfig(tenantID TenantID, section string) (ConfigProvider, error)
GetTenantConfig retrieves a configuration for a specific tenant and section
func (*TenantConfigProvider) HasTenantConfig ¶ added in v1.1.0
func (tcp *TenantConfigProvider) HasTenantConfig(tenantID TenantID, section string) bool
HasTenantConfig checks if a configuration exists for a specific tenant and section
func (*TenantConfigProvider) SetTenantConfig ¶ added in v1.1.0
func (tcp *TenantConfigProvider) SetTenantConfig(tenantID TenantID, section string, provider ConfigProvider)
SetTenantConfig sets a configuration for a specific tenant and section
type TenantContext ¶ added in v1.1.0
TenantContext is a context for tenant-aware operations
func NewTenantContext ¶ added in v1.1.0
func NewTenantContext(ctx context.Context, tenantID TenantID) *TenantContext
NewTenantContext creates a new context with tenant information
func (*TenantContext) GetTenantID ¶ added in v1.1.0
func (tc *TenantContext) GetTenantID() TenantID
GetTenantID returns the tenant ID from the context
type TenantService ¶ added in v1.1.0
type TenantService interface {
// GetTenantConfig returns tenant-specific config for the given tenant and section
GetTenantConfig(tenantID TenantID, section string) (ConfigProvider, error)
// GetTenants returns all tenant IDs
GetTenants() []TenantID
// RegisterTenant registers a new tenant with optional initial configs
RegisterTenant(tenantID TenantID, configs map[string]ConfigProvider) error
// RegisterTenantAwareModule registers a module that wants to be notified about tenant lifecycle events
RegisterTenantAwareModule(module TenantAwareModule) error
}
TenantService provides tenant management functionality
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
modcli
module
|
|
|
modules
|
|
|
auth
module
|
|
|
cache
module
|
|
|
chimux
module
|
|
|
database
module
|
|
|
eventbus
module
|
|
|
eventlogger
module
|
|
|
httpclient
module
|
|
|
httpserver
module
|
|
|
jsonschema
module
|
|
|
letsencrypt
module
|
|
|
logmasker
module
|
|
|
reverseproxy
module
|
|
|
scheduler
module
|