Documentation
¶
Index ¶
- func Configure[T any](services di.IServiceCollection, section string)
- func ConfigureWithDefaults[T any](services di.IServiceCollection, section string, defaults func() *T)
- func ConfigureWithValidation[T any](services di.IServiceCollection, section string, validator func(*T) error)
- func GetValue[T any](config IConfiguration, key string, defaultValue T) T
- func GetValueOrError[T any](config IConfiguration, key string, defaultValue T) (T, error)
- func MustGetValue[T any](config IConfiguration, key string) T
- func OnChange(producer func() IChangeToken, changeCallback func())
- type BinderOptions
- type ChangeToken
- type CommandLineConfigurationProvider
- type CommandLineConfigurationSource
- type Configuration
- func (c *Configuration) Bind(section string, target interface{}) error
- func (c *Configuration) BindWithOptions(section string, target interface{}, options *BinderOptions) error
- func (c *Configuration) Exists(key string) bool
- func (c *Configuration) Get(key string) string
- func (c *Configuration) GetBool(key string, defaultValue bool) bool
- func (c *Configuration) GetChildren() []IConfigurationSection
- func (c *Configuration) GetDebugView() string
- func (c *Configuration) GetFloat64(key string, defaultValue float64) float64
- func (c *Configuration) GetInt(key string, defaultValue int) int
- func (c *Configuration) GetInt64(key string, defaultValue int64) int64
- func (c *Configuration) GetRequiredSection(key string) IConfigurationSection
- func (c *Configuration) GetSection(key string) IConfigurationSection
- func (c *Configuration) GetString(key string, defaultValue string) string
- func (c *Configuration) OnChange(callback func())
- func (c *Configuration) Providers() []IConfigurationProvider
- func (c *Configuration) Reload()
- func (c *Configuration) Set(key string, value string)
- type ConfigurationBuilder
- func (b *ConfigurationBuilder) AddCommandLine(args []string) IConfigurationBuilder
- func (b *ConfigurationBuilder) AddEnvironmentVariables(prefix string) IConfigurationBuilder
- func (b *ConfigurationBuilder) AddInMemoryCollection(data map[string]string) IConfigurationBuilder
- func (b *ConfigurationBuilder) AddIniFile(path string, optional bool, reloadOnChange bool) IConfigurationBuilder
- func (b *ConfigurationBuilder) AddJsonFile(path string, optional bool, reloadOnChange bool) IConfigurationBuilder
- func (b *ConfigurationBuilder) AddKeyPerFile(directoryPath string, optional bool) IConfigurationBuilder
- func (b *ConfigurationBuilder) AddXmlFile(path string, optional bool, reloadOnChange bool) IConfigurationBuilder
- func (b *ConfigurationBuilder) AddYamlFile(path string, optional bool, reloadOnChange bool) IConfigurationBuilder
- func (b *ConfigurationBuilder) Build() IConfiguration
- func (b *ConfigurationBuilder) GetBasePath() string
- func (b *ConfigurationBuilder) Properties() map[string]interface{}
- func (b *ConfigurationBuilder) SetBasePath(basePath string) IConfigurationBuilder
- func (b *ConfigurationBuilder) Sources() []IConfigurationSource
- type ConfigurationManager
- func (m *ConfigurationManager) AddCommandLine(args []string) IConfigurationBuilder
- func (m *ConfigurationManager) AddEnvironmentVariables(prefix string) IConfigurationBuilder
- func (m *ConfigurationManager) AddInMemoryCollection(data map[string]string) IConfigurationBuilder
- func (m *ConfigurationManager) AddIniFile(path string, optional bool, reloadOnChange bool) IConfigurationBuilder
- func (m *ConfigurationManager) AddJsonFile(path string, optional bool, reloadOnChange bool) IConfigurationBuilder
- func (m *ConfigurationManager) AddKeyPerFile(directoryPath string, optional bool) IConfigurationBuilder
- func (m *ConfigurationManager) AddXmlFile(path string, optional bool, reloadOnChange bool) IConfigurationBuilder
- func (m *ConfigurationManager) AddYamlFile(path string, optional bool, reloadOnChange bool) IConfigurationBuilder
- func (m *ConfigurationManager) Bind(section string, target interface{}) error
- func (m *ConfigurationManager) BindWithOptions(section string, target interface{}, options *BinderOptions) error
- func (m *ConfigurationManager) Build() IConfiguration
- func (m *ConfigurationManager) Exists(key string) bool
- func (m *ConfigurationManager) Get(key string) string
- func (m *ConfigurationManager) GetBasePath() string
- func (m *ConfigurationManager) GetBool(key string, defaultValue bool) bool
- func (m *ConfigurationManager) GetChildren() []IConfigurationSection
- func (m *ConfigurationManager) GetDebugView() string
- func (m *ConfigurationManager) GetFloat64(key string, defaultValue float64) float64
- func (m *ConfigurationManager) GetInt(key string, defaultValue int) int
- func (m *ConfigurationManager) GetInt64(key string, defaultValue int64) int64
- func (m *ConfigurationManager) GetRequiredSection(key string) IConfigurationSection
- func (m *ConfigurationManager) GetSection(key string) IConfigurationSection
- func (m *ConfigurationManager) GetString(key string, defaultValue string) string
- func (m *ConfigurationManager) OnChange(callback func())
- func (m *ConfigurationManager) Properties() map[string]interface{}
- func (m *ConfigurationManager) Providers() []IConfigurationProvider
- func (m *ConfigurationManager) Reload()
- func (m *ConfigurationManager) Set(key string, value string)
- func (m *ConfigurationManager) SetBasePath(basePath string) IConfigurationBuilder
- func (m *ConfigurationManager) Sources() []IConfigurationSource
- type ConfigurationProvider
- func (p *ConfigurationProvider) GetData() map[string]string
- func (p *ConfigurationProvider) GetReloadToken() IChangeToken
- func (p *ConfigurationProvider) Load() map[string]string
- func (p *ConfigurationProvider) Set(key, value string)
- func (p *ConfigurationProvider) SetData(data map[string]string)
- func (p *ConfigurationProvider) TryGet(key string) (string, bool)
- type ConfigurationSection
- func (s *ConfigurationSection) Bind(section string, target interface{}) error
- func (s *ConfigurationSection) BindWithOptions(section string, target interface{}, options *BinderOptions) error
- func (s *ConfigurationSection) Exists(key string) bool
- func (s *ConfigurationSection) Get(key string) string
- func (s *ConfigurationSection) GetBool(key string, defaultValue bool) bool
- func (s *ConfigurationSection) GetChildren() []IConfigurationSection
- func (s *ConfigurationSection) GetFloat64(key string, defaultValue float64) float64
- func (s *ConfigurationSection) GetInt(key string, defaultValue int) int
- func (s *ConfigurationSection) GetInt64(key string, defaultValue int64) int64
- func (s *ConfigurationSection) GetRequiredSection(key string) IConfigurationSection
- func (s *ConfigurationSection) GetSection(key string) IConfigurationSection
- func (s *ConfigurationSection) GetString(key string, defaultValue string) string
- func (s *ConfigurationSection) Key() string
- func (s *ConfigurationSection) OnChange(callback func())
- func (s *ConfigurationSection) Path() string
- func (s *ConfigurationSection) Set(key string, value string)
- func (s *ConfigurationSection) Value() string
- type EnvironmentVariablesConfigurationProvider
- type EnvironmentVariablesConfigurationSource
- type FileWatcher
- type IChangeToken
- type IConfiguration
- type IConfigurationBuilder
- type IConfigurationManager
- type IConfigurationProvider
- type IConfigurationRoot
- type IConfigurationSection
- type IConfigurationSource
- type IDisposable
- type IOptionsMonitor
- type IReloadableSource
- type InMemoryConfigurationProvider
- type InMemoryConfigurationSource
- type IniConfigurationProvider
- type IniConfigurationSource
- type JsonConfigurationProvider
- type JsonConfigurationSource
- type KeyPerFileConfigurationProvider
- type KeyPerFileConfigurationSource
- type OptionsMonitor
- type XmlConfigurationProvider
- type XmlConfigurationSource
- type YamlConfigurationProvider
- type YamlConfigurationSource
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Configure ¶
func Configure[T any](services di.IServiceCollection, section string)
Configure registers configuration instance T with the DI container. It binds the configuration to the specified section and registers IOptionsMonitor[T] and T itself. Corresponds to .NET services.Configure<T>(config.GetSection(...)).
This function registers both the Options pattern (IOptionsMonitor[T]) and direct injection (T), allowing services to choose their preferred injection style.
Usage:
config.Configure[AppSettings](services, "App") config.Configure[Config](services, "") // bind root configuration
Injection styles:
// Style 1: Options pattern with hot reload support
type Service1 struct {
config IOptionsMonitor[AppSettings]
}
// Style 2: Direct injection (value snapshot)
type Service2 struct {
config AppSettings
}
func ConfigureWithDefaults ¶
func ConfigureWithDefaults[T any](services di.IServiceCollection, section string, defaults func() *T)
ConfigureWithDefaults registers configuration with default values. The defaults are applied first, then overwritten by configuration values. Corresponds to .NET services.Configure<T>() with default values.
Usage:
config.ConfigureWithDefaults[AppSettings](services, "App", func() *AppSettings {
return &AppSettings{
Timeout: 30,
MaxRetries: 3,
}
})
func ConfigureWithValidation ¶
func ConfigureWithValidation[T any](services di.IServiceCollection, section string, validator func(*T) error)
ConfigureWithValidation registers configuration with validation. Validation is performed when the options are resolved from DI. Corresponds to .NET services.AddOptions<T>().Validate(...).
Usage:
config.ConfigureWithValidation[EmailSettings](services, "Email", func(opts *EmailSettings) error {
if opts.SmtpHost == "" {
return fmt.Errorf("SMTP host is required")
}
return nil
})
func GetValue ¶
func GetValue[T any](config IConfiguration, key string, defaultValue T) T
GetValue is a generic function to get a configuration value with type safety. It supports common types and custom types that can be parsed from strings.
Usage:
port := config.GetValue(config, "server:port", 8080) host := config.GetValue(config, "server:host", "localhost") timeout := config.GetValue(config, "timeout", 30*time.Second)
func GetValueOrError ¶
func GetValueOrError[T any](config IConfiguration, key string, defaultValue T) (T, error)
GetValueOrError gets a configuration value or returns an error if conversion fails.
Usage:
port, err := config.GetValueOrError[int](config, "server:port", 8080)
if err != nil {
log.Fatal(err)
}
func MustGetValue ¶
func MustGetValue[T any](config IConfiguration, key string) T
MustGetValue is like GetValue but panics if the key doesn't exist.
Usage:
port := config.MustGetValue[int](config, "server:port")
func OnChange ¶
func OnChange(producer func() IChangeToken, changeCallback func())
OnChange registers a callback to be invoked when a change token producer reports a change.
Types ¶
type BinderOptions ¶
type BinderOptions struct {
// BindNonPublicProperties indicates whether to bind non-public properties.
BindNonPublicProperties bool
// ErrorOnUnknownConfiguration indicates whether to error on unknown configuration keys.
ErrorOnUnknownConfiguration bool
}
BinderOptions contains options for configuration binding.
type ChangeToken ¶
type ChangeToken struct {
// contains filtered or unexported fields
}
ChangeToken is the default implementation of IChangeToken.
func (*ChangeToken) HasChanged ¶
func (t *ChangeToken) HasChanged() bool
HasChanged returns true if the token has changed.
func (*ChangeToken) RegisterChangeCallback ¶
func (t *ChangeToken) RegisterChangeCallback(callback func(interface{}), state interface{}) IDisposable
RegisterChangeCallback registers a callback to be invoked when the token changes.
func (*ChangeToken) SignalChange ¶
func (t *ChangeToken) SignalChange()
SignalChange signals that the token has changed.
type CommandLineConfigurationProvider ¶
type CommandLineConfigurationProvider struct {
*ConfigurationProvider
// contains filtered or unexported fields
}
CommandLineConfigurationProvider is a provider for command line arguments.
func (*CommandLineConfigurationProvider) Load ¶
func (p *CommandLineConfigurationProvider) Load() map[string]string
Load loads configuration from command line arguments.
type CommandLineConfigurationSource ¶
type CommandLineConfigurationSource struct {
Args []string
SwitchMappings map[string]string // Maps short options to full keys, e.g. {"-p": "Port"}
}
CommandLineConfigurationSource represents command line arguments configuration source.
func (*CommandLineConfigurationSource) Build ¶
func (s *CommandLineConfigurationSource) Build(builder IConfigurationBuilder) IConfigurationProvider
Build builds an IConfigurationProvider from the command line source.
type Configuration ¶
type Configuration struct {
// contains filtered or unexported fields
}
Configuration is the default implementation of IConfiguration.
func (*Configuration) Bind ¶
func (c *Configuration) Bind(section string, target interface{}) error
Bind binds a configuration section to a target object.
func (*Configuration) BindWithOptions ¶
func (c *Configuration) BindWithOptions(section string, target interface{}, options *BinderOptions) error
BindWithOptions binds a configuration section to a target object with options.
func (*Configuration) Exists ¶
func (c *Configuration) Exists(key string) bool
Exists checks if the configuration key exists.
func (*Configuration) Get ¶
func (c *Configuration) Get(key string) string
Get gets a configuration value by key.
func (*Configuration) GetBool ¶
func (c *Configuration) GetBool(key string, defaultValue bool) bool
GetBool gets a boolean configuration value.
func (*Configuration) GetChildren ¶
func (c *Configuration) GetChildren() []IConfigurationSection
GetChildren gets the immediate descendant configuration sub-sections.
func (*Configuration) GetDebugView ¶
func (c *Configuration) GetDebugView() string
GetDebugView gets a debug view of the configuration.
func (*Configuration) GetFloat64 ¶
func (c *Configuration) GetFloat64(key string, defaultValue float64) float64
GetFloat64 gets a float64 configuration value.
func (*Configuration) GetInt ¶
func (c *Configuration) GetInt(key string, defaultValue int) int
GetInt gets an integer configuration value.
func (*Configuration) GetInt64 ¶
func (c *Configuration) GetInt64(key string, defaultValue int64) int64
GetInt64 gets an int64 configuration value.
func (*Configuration) GetRequiredSection ¶
func (c *Configuration) GetRequiredSection(key string) IConfigurationSection
GetRequiredSection gets a required configuration sub-section.
func (*Configuration) GetSection ¶
func (c *Configuration) GetSection(key string) IConfigurationSection
GetSection gets a configuration sub-section.
func (*Configuration) GetString ¶
func (c *Configuration) GetString(key string, defaultValue string) string
GetString gets a string configuration value.
func (*Configuration) OnChange ¶
func (c *Configuration) OnChange(callback func())
OnChange registers a callback for configuration changes.
func (*Configuration) Providers ¶
func (c *Configuration) Providers() []IConfigurationProvider
Providers returns the configuration providers.
func (*Configuration) Reload ¶
func (c *Configuration) Reload()
Reload reloads the configuration from all providers.
func (*Configuration) Set ¶
func (c *Configuration) Set(key string, value string)
Set sets a configuration value.
type ConfigurationBuilder ¶
type ConfigurationBuilder struct {
// contains filtered or unexported fields
}
ConfigurationBuilder is the default implementation of IConfigurationBuilder.
func (*ConfigurationBuilder) AddCommandLine ¶
func (b *ConfigurationBuilder) AddCommandLine(args []string) IConfigurationBuilder
AddCommandLine adds command line arguments as a configuration source.
func (*ConfigurationBuilder) AddEnvironmentVariables ¶
func (b *ConfigurationBuilder) AddEnvironmentVariables(prefix string) IConfigurationBuilder
AddEnvironmentVariables adds environment variables as a configuration source.
func (*ConfigurationBuilder) AddInMemoryCollection ¶
func (b *ConfigurationBuilder) AddInMemoryCollection(data map[string]string) IConfigurationBuilder
AddInMemoryCollection adds an in-memory collection as a configuration source.
func (*ConfigurationBuilder) AddIniFile ¶
func (b *ConfigurationBuilder) AddIniFile(path string, optional bool, reloadOnChange bool) IConfigurationBuilder
AddIniFile adds an INI configuration source.
func (*ConfigurationBuilder) AddJsonFile ¶
func (b *ConfigurationBuilder) AddJsonFile(path string, optional bool, reloadOnChange bool) IConfigurationBuilder
AddJsonFile adds a JSON configuration source.
func (*ConfigurationBuilder) AddKeyPerFile ¶
func (b *ConfigurationBuilder) AddKeyPerFile(directoryPath string, optional bool) IConfigurationBuilder
AddKeyPerFile adds a key-per-file configuration source.
func (*ConfigurationBuilder) AddXmlFile ¶
func (b *ConfigurationBuilder) AddXmlFile(path string, optional bool, reloadOnChange bool) IConfigurationBuilder
AddXmlFile adds an XML configuration source.
func (*ConfigurationBuilder) AddYamlFile ¶
func (b *ConfigurationBuilder) AddYamlFile(path string, optional bool, reloadOnChange bool) IConfigurationBuilder
AddYamlFile adds a YAML configuration source.
func (*ConfigurationBuilder) Build ¶
func (b *ConfigurationBuilder) Build() IConfiguration
Build builds the configuration.
func (*ConfigurationBuilder) GetBasePath ¶
func (b *ConfigurationBuilder) GetBasePath() string
GetBasePath gets the base path for file-based configuration sources.
func (*ConfigurationBuilder) Properties ¶
func (b *ConfigurationBuilder) Properties() map[string]interface{}
Properties returns the shared properties dictionary.
func (*ConfigurationBuilder) SetBasePath ¶
func (b *ConfigurationBuilder) SetBasePath(basePath string) IConfigurationBuilder
SetBasePath sets the base path for file-based configuration sources.
func (*ConfigurationBuilder) Sources ¶
func (b *ConfigurationBuilder) Sources() []IConfigurationSource
Sources returns the configuration sources.
type ConfigurationManager ¶
type ConfigurationManager struct {
// contains filtered or unexported fields
}
ConfigurationManager is a mutable configuration object that can be used to both build and read configuration. It implements IConfiguration, IConfigurationBuilder, and IConfigurationRoot.
func (*ConfigurationManager) AddCommandLine ¶
func (m *ConfigurationManager) AddCommandLine(args []string) IConfigurationBuilder
AddCommandLine adds command line arguments as a configuration source.
func (*ConfigurationManager) AddEnvironmentVariables ¶
func (m *ConfigurationManager) AddEnvironmentVariables(prefix string) IConfigurationBuilder
AddEnvironmentVariables adds environment variables as a configuration source.
func (*ConfigurationManager) AddInMemoryCollection ¶
func (m *ConfigurationManager) AddInMemoryCollection(data map[string]string) IConfigurationBuilder
AddInMemoryCollection adds an in-memory collection as a configuration source.
func (*ConfigurationManager) AddIniFile ¶
func (m *ConfigurationManager) AddIniFile(path string, optional bool, reloadOnChange bool) IConfigurationBuilder
AddIniFile adds an INI configuration source.
func (*ConfigurationManager) AddJsonFile ¶
func (m *ConfigurationManager) AddJsonFile(path string, optional bool, reloadOnChange bool) IConfigurationBuilder
AddJsonFile adds a JSON configuration source.
func (*ConfigurationManager) AddKeyPerFile ¶
func (m *ConfigurationManager) AddKeyPerFile(directoryPath string, optional bool) IConfigurationBuilder
AddKeyPerFile adds a key-per-file configuration source.
func (*ConfigurationManager) AddXmlFile ¶
func (m *ConfigurationManager) AddXmlFile(path string, optional bool, reloadOnChange bool) IConfigurationBuilder
AddXmlFile adds an XML configuration source.
func (*ConfigurationManager) AddYamlFile ¶
func (m *ConfigurationManager) AddYamlFile(path string, optional bool, reloadOnChange bool) IConfigurationBuilder
AddYamlFile adds a YAML configuration source.
func (*ConfigurationManager) Bind ¶
func (m *ConfigurationManager) Bind(section string, target interface{}) error
Bind binds a configuration section to a target object.
func (*ConfigurationManager) BindWithOptions ¶
func (m *ConfigurationManager) BindWithOptions(section string, target interface{}, options *BinderOptions) error
BindWithOptions binds a configuration section to a target object with options.
func (*ConfigurationManager) Build ¶
func (m *ConfigurationManager) Build() IConfiguration
Build builds the configuration.
func (*ConfigurationManager) Exists ¶
func (m *ConfigurationManager) Exists(key string) bool
Exists checks if the configuration key exists.
func (*ConfigurationManager) Get ¶
func (m *ConfigurationManager) Get(key string) string
Get gets a configuration value by key.
func (*ConfigurationManager) GetBasePath ¶
func (m *ConfigurationManager) GetBasePath() string
GetBasePath gets the base path for file-based configuration sources.
func (*ConfigurationManager) GetBool ¶
func (m *ConfigurationManager) GetBool(key string, defaultValue bool) bool
GetBool gets a boolean configuration value.
func (*ConfigurationManager) GetChildren ¶
func (m *ConfigurationManager) GetChildren() []IConfigurationSection
GetChildren gets the immediate descendant configuration sub-sections.
func (*ConfigurationManager) GetDebugView ¶
func (m *ConfigurationManager) GetDebugView() string
GetDebugView gets a debug view of the configuration.
func (*ConfigurationManager) GetFloat64 ¶
func (m *ConfigurationManager) GetFloat64(key string, defaultValue float64) float64
GetFloat64 gets a float64 configuration value.
func (*ConfigurationManager) GetInt ¶
func (m *ConfigurationManager) GetInt(key string, defaultValue int) int
GetInt gets an integer configuration value.
func (*ConfigurationManager) GetInt64 ¶
func (m *ConfigurationManager) GetInt64(key string, defaultValue int64) int64
GetInt64 gets an int64 configuration value.
func (*ConfigurationManager) GetRequiredSection ¶
func (m *ConfigurationManager) GetRequiredSection(key string) IConfigurationSection
GetRequiredSection gets a required configuration sub-section.
func (*ConfigurationManager) GetSection ¶
func (m *ConfigurationManager) GetSection(key string) IConfigurationSection
GetSection gets a configuration sub-section.
func (*ConfigurationManager) GetString ¶
func (m *ConfigurationManager) GetString(key string, defaultValue string) string
GetString gets a string configuration value.
func (*ConfigurationManager) OnChange ¶
func (m *ConfigurationManager) OnChange(callback func())
OnChange registers a callback for configuration changes.
func (*ConfigurationManager) Properties ¶
func (m *ConfigurationManager) Properties() map[string]interface{}
Properties returns the shared properties dictionary.
func (*ConfigurationManager) Providers ¶
func (m *ConfigurationManager) Providers() []IConfigurationProvider
Providers returns the configuration providers.
func (*ConfigurationManager) Reload ¶
func (m *ConfigurationManager) Reload()
Reload reloads the configuration from all providers.
func (*ConfigurationManager) Set ¶
func (m *ConfigurationManager) Set(key string, value string)
Set sets a configuration value.
func (*ConfigurationManager) SetBasePath ¶
func (m *ConfigurationManager) SetBasePath(basePath string) IConfigurationBuilder
SetBasePath sets the base path for file-based configuration sources.
func (*ConfigurationManager) Sources ¶
func (m *ConfigurationManager) Sources() []IConfigurationSource
Sources returns the configuration sources.
type ConfigurationProvider ¶
type ConfigurationProvider struct {
// contains filtered or unexported fields
}
ConfigurationProvider is the base implementation of IConfigurationProvider.
func NewConfigurationProvider ¶
func NewConfigurationProvider() *ConfigurationProvider
NewConfigurationProvider creates a new ConfigurationProvider.
func (*ConfigurationProvider) GetData ¶
func (p *ConfigurationProvider) GetData() map[string]string
GetData gets the provider's data (for derived classes).
func (*ConfigurationProvider) GetReloadToken ¶
func (p *ConfigurationProvider) GetReloadToken() IChangeToken
GetReloadToken gets a change token for observing configuration changes.
func (*ConfigurationProvider) Load ¶
func (p *ConfigurationProvider) Load() map[string]string
Load loads configuration key/values.
func (*ConfigurationProvider) Set ¶
func (p *ConfigurationProvider) Set(key, value string)
Set sets a configuration value.
func (*ConfigurationProvider) SetData ¶
func (p *ConfigurationProvider) SetData(data map[string]string)
SetData sets the provider's data (for derived classes).
type ConfigurationSection ¶
type ConfigurationSection struct {
// contains filtered or unexported fields
}
ConfigurationSection represents a section of configuration.
func (*ConfigurationSection) Bind ¶
func (s *ConfigurationSection) Bind(section string, target interface{}) error
Bind binds this section to a target object.
func (*ConfigurationSection) BindWithOptions ¶
func (s *ConfigurationSection) BindWithOptions(section string, target interface{}, options *BinderOptions) error
BindWithOptions binds this section to a target object with options.
func (*ConfigurationSection) Exists ¶
func (s *ConfigurationSection) Exists(key string) bool
Exists checks if the configuration key exists.
func (*ConfigurationSection) Get ¶
func (s *ConfigurationSection) Get(key string) string
Get gets a configuration value by key.
func (*ConfigurationSection) GetBool ¶
func (s *ConfigurationSection) GetBool(key string, defaultValue bool) bool
GetBool gets a boolean configuration value.
func (*ConfigurationSection) GetChildren ¶
func (s *ConfigurationSection) GetChildren() []IConfigurationSection
GetChildren gets the immediate descendant configuration sub-sections.
func (*ConfigurationSection) GetFloat64 ¶
func (s *ConfigurationSection) GetFloat64(key string, defaultValue float64) float64
GetFloat64 gets a float64 configuration value.
func (*ConfigurationSection) GetInt ¶
func (s *ConfigurationSection) GetInt(key string, defaultValue int) int
GetInt gets an integer configuration value.
func (*ConfigurationSection) GetInt64 ¶
func (s *ConfigurationSection) GetInt64(key string, defaultValue int64) int64
GetInt64 gets an int64 configuration value.
func (*ConfigurationSection) GetRequiredSection ¶
func (s *ConfigurationSection) GetRequiredSection(key string) IConfigurationSection
GetRequiredSection gets a required configuration sub-section.
func (*ConfigurationSection) GetSection ¶
func (s *ConfigurationSection) GetSection(key string) IConfigurationSection
GetSection gets a configuration sub-section.
func (*ConfigurationSection) GetString ¶
func (s *ConfigurationSection) GetString(key string, defaultValue string) string
GetString gets a string configuration value.
func (*ConfigurationSection) Key ¶
func (s *ConfigurationSection) Key() string
Key gets the key this section occupies in its parent.
func (*ConfigurationSection) OnChange ¶
func (s *ConfigurationSection) OnChange(callback func())
OnChange registers a callback for configuration changes.
func (*ConfigurationSection) Path ¶
func (s *ConfigurationSection) Path() string
Path gets the full path to this section.
func (*ConfigurationSection) Set ¶
func (s *ConfigurationSection) Set(key string, value string)
Set sets a configuration value.
func (*ConfigurationSection) Value ¶
func (s *ConfigurationSection) Value() string
Value gets the section value.
type EnvironmentVariablesConfigurationProvider ¶
type EnvironmentVariablesConfigurationProvider struct {
*ConfigurationProvider
// contains filtered or unexported fields
}
EnvironmentVariablesConfigurationProvider is a provider for environment variables.
func (*EnvironmentVariablesConfigurationProvider) Load ¶
func (p *EnvironmentVariablesConfigurationProvider) Load() map[string]string
Load loads configuration from environment variables.
type EnvironmentVariablesConfigurationSource ¶
type EnvironmentVariablesConfigurationSource struct {
Prefix string
KeyDelimiter string // Custom delimiter for key separator, defaults to "__"
}
EnvironmentVariablesConfigurationSource represents environment variables configuration source.
func (*EnvironmentVariablesConfigurationSource) Build ¶
func (s *EnvironmentVariablesConfigurationSource) Build(builder IConfigurationBuilder) IConfigurationProvider
Build builds an IConfigurationProvider from the environment variables source.
type FileWatcher ¶
type FileWatcher struct {
// contains filtered or unexported fields
}
FileWatcher watches a file for changes and calls a callback when changes are detected.
func NewFileWatcher ¶
func NewFileWatcher(path string, callback func()) *FileWatcher
NewFileWatcher creates a new FileWatcher for the specified file path.
func NewFileWatcherWithInterval ¶
func NewFileWatcherWithInterval(path string, interval time.Duration, callback func()) *FileWatcher
NewFileWatcherWithInterval creates a new FileWatcher with a custom check interval.
func (*FileWatcher) IsRunning ¶
func (w *FileWatcher) IsRunning() bool
IsRunning returns true if the watcher is still running.
type IChangeToken ¶
type IChangeToken interface {
// HasChanged returns true if the token has changed.
HasChanged() bool
// RegisterChangeCallback registers a callback to be invoked when the token changes.
RegisterChangeCallback(callback func(interface{}), state interface{}) IDisposable
}
IChangeToken represents a token that can be used to track configuration changes.
type IConfiguration ¶
type IConfiguration interface {
// Get gets a configuration value by key.
Get(key string) string
// GetSection gets a configuration sub-section.
GetSection(key string) IConfigurationSection
// GetRequiredSection gets a required configuration sub-section (panics if not exists).
GetRequiredSection(key string) IConfigurationSection
// Bind binds a configuration section to a target object.
Bind(section string, target interface{}) error
// BindWithOptions binds a configuration section to a target object with options.
BindWithOptions(section string, target interface{}, options *BinderOptions) error
// OnChange registers a callback for configuration changes.
OnChange(callback func())
// GetChildren gets the immediate descendant configuration sub-sections.
GetChildren() []IConfigurationSection
// Set sets a configuration value (for in-memory configuration).
Set(key string, value string)
// GetString gets a string configuration value.
GetString(key string, defaultValue string) string
// GetInt gets an integer configuration value.
GetInt(key string, defaultValue int) int
// GetInt64 gets an int64 configuration value.
GetInt64(key string, defaultValue int64) int64
// GetBool gets a boolean configuration value.
GetBool(key string, defaultValue bool) bool
// GetFloat64 gets a float64 configuration value.
GetFloat64(key string, defaultValue float64) float64
// Exists checks if the configuration key exists.
Exists(key string) bool
}
IConfiguration represents a set of key/value application configuration properties.
func NewConfiguration ¶
func NewConfiguration() IConfiguration
NewConfiguration creates a new Configuration instance.
type IConfigurationBuilder ¶
type IConfigurationBuilder interface {
// AddJsonFile adds a JSON configuration source.
AddJsonFile(path string, optional bool, reloadOnChange bool) IConfigurationBuilder
// AddYamlFile adds a YAML configuration source.
AddYamlFile(path string, optional bool, reloadOnChange bool) IConfigurationBuilder
// AddIniFile adds an INI configuration source.
AddIniFile(path string, optional bool, reloadOnChange bool) IConfigurationBuilder
// AddXmlFile adds an XML configuration source.
AddXmlFile(path string, optional bool, reloadOnChange bool) IConfigurationBuilder
// AddKeyPerFile adds a key-per-file configuration source.
AddKeyPerFile(directoryPath string, optional bool) IConfigurationBuilder
// AddEnvironmentVariables adds environment variables as a configuration source.
AddEnvironmentVariables(prefix string) IConfigurationBuilder
// AddCommandLine adds command line arguments as a configuration source.
AddCommandLine(args []string) IConfigurationBuilder
// AddInMemoryCollection adds an in-memory collection as a configuration source.
AddInMemoryCollection(data map[string]string) IConfigurationBuilder
// SetBasePath sets the base path for file-based configuration sources.
SetBasePath(basePath string) IConfigurationBuilder
// GetBasePath gets the base path for file-based configuration sources.
GetBasePath() string
// Properties returns the shared properties dictionary.
Properties() map[string]interface{}
// Sources returns the configuration sources.
Sources() []IConfigurationSource
// Build builds the configuration.
Build() IConfiguration
}
IConfigurationBuilder represents a type used to build application configuration.
func NewConfigurationBuilder ¶
func NewConfigurationBuilder() IConfigurationBuilder
NewConfigurationBuilder creates a new configuration builder.
type IConfigurationManager ¶
type IConfigurationManager interface {
IConfiguration
IConfigurationBuilder
IConfigurationRoot
}
IConfigurationManager combines configuration reading, building, and root functionality.
func NewConfigurationManager ¶
func NewConfigurationManager() IConfigurationManager
NewConfigurationManager creates a new ConfigurationManager.
type IConfigurationProvider ¶
type IConfigurationProvider interface {
// Load loads configuration key/values from the source.
Load() map[string]string
// TryGet tries to get a configuration value by key.
TryGet(key string) (string, bool)
// Set sets a configuration value.
Set(key, value string)
// GetReloadToken gets a change token that can be used to observe configuration changes.
GetReloadToken() IChangeToken
}
IConfigurationProvider represents a provider of configuration key/values.
type IConfigurationRoot ¶
type IConfigurationRoot interface {
IConfiguration
// Reload reloads the configuration from all providers.
Reload()
// GetDebugView gets a debug view of the configuration.
GetDebugView() string
// Providers returns the configuration providers.
Providers() []IConfigurationProvider
}
IConfigurationRoot represents the root of a configuration hierarchy.
func NewConfigurationRoot ¶
func NewConfigurationRoot(providers []IConfigurationProvider) IConfigurationRoot
NewConfigurationRoot creates a new ConfigurationRoot instance.
type IConfigurationSection ¶
type IConfigurationSection interface {
IConfiguration
// Key gets the key this section occupies in its parent.
Key() string
// Path gets the full path to this section from the IConfigurationRoot.
Path() string
// Value gets or sets the section value.
Value() string
}
IConfigurationSection represents a section of application configuration values.
type IConfigurationSource ¶
type IConfigurationSource interface {
// Build builds an IConfigurationProvider from the source.
Build(builder IConfigurationBuilder) IConfigurationProvider
}
IConfigurationSource represents a source of configuration key/values.
type IDisposable ¶
type IDisposable interface {
Dispose()
}
IDisposable represents a resource that can be disposed.
type IOptionsMonitor ¶
type IOptionsMonitor[T any] interface { // CurrentValue returns the current configured value. CurrentValue() *T // Get returns the configured value for the specified name. Get(name string) *T // OnChange registers a listener to be called whenever a named T changes. OnChange(listener func(*T, string)) }
IOptionsMonitor is used for notifications when T instances change. This is the unified configuration interface that supports hot reload.
func NewOptionsMonitor ¶
func NewOptionsMonitor[T any](initialValue *T) IOptionsMonitor[T]
NewOptionsMonitor creates a new OptionsMonitor instance.
type IReloadableSource ¶
IReloadableSource represents a configuration source that supports reloading.
type InMemoryConfigurationProvider ¶
type InMemoryConfigurationProvider struct {
*ConfigurationProvider
// contains filtered or unexported fields
}
InMemoryConfigurationProvider is a provider for in-memory configuration.
func (*InMemoryConfigurationProvider) Load ¶
func (p *InMemoryConfigurationProvider) Load() map[string]string
Load returns the in-memory configuration data.
type InMemoryConfigurationSource ¶
InMemoryConfigurationSource represents an in-memory configuration source.
func (*InMemoryConfigurationSource) Build ¶
func (s *InMemoryConfigurationSource) Build(builder IConfigurationBuilder) IConfigurationProvider
Build builds an IConfigurationProvider from the in-memory source.
type IniConfigurationProvider ¶
type IniConfigurationProvider struct {
*ConfigurationProvider
// contains filtered or unexported fields
}
IniConfigurationProvider is a provider for INI configuration files.
func (*IniConfigurationProvider) Load ¶
func (p *IniConfigurationProvider) Load() map[string]string
Load loads configuration from INI file.
type IniConfigurationSource ¶
IniConfigurationSource represents an INI file configuration source.
func (*IniConfigurationSource) Build ¶
func (s *IniConfigurationSource) Build(builder IConfigurationBuilder) IConfigurationProvider
Build builds an IConfigurationProvider from the INI source.
type JsonConfigurationProvider ¶
type JsonConfigurationProvider struct {
*ConfigurationProvider
// contains filtered or unexported fields
}
JsonConfigurationProvider is a provider for JSON configuration files.
func (*JsonConfigurationProvider) Load ¶
func (p *JsonConfigurationProvider) Load() map[string]string
Load loads configuration from JSON file.
type JsonConfigurationSource ¶
JsonConfigurationSource represents a JSON file configuration source.
func (*JsonConfigurationSource) Build ¶
func (s *JsonConfigurationSource) Build(builder IConfigurationBuilder) IConfigurationProvider
Build builds an IConfigurationProvider from the JSON source.
type KeyPerFileConfigurationProvider ¶
type KeyPerFileConfigurationProvider struct {
*ConfigurationProvider
// contains filtered or unexported fields
}
KeyPerFileConfigurationProvider is a provider for key-per-file configuration.
func (*KeyPerFileConfigurationProvider) Load ¶
func (p *KeyPerFileConfigurationProvider) Load() map[string]string
Load loads configuration from files in a directory.
type KeyPerFileConfigurationSource ¶
KeyPerFileConfigurationSource represents a configuration source where each file in a directory represents a configuration key, and the file content is the value.
func (*KeyPerFileConfigurationSource) Build ¶
func (s *KeyPerFileConfigurationSource) Build(builder IConfigurationBuilder) IConfigurationProvider
Build builds an IConfigurationProvider from the key-per-file source.
type OptionsMonitor ¶
type OptionsMonitor[T any] struct { // contains filtered or unexported fields }
OptionsMonitor implements IOptionsMonitor[T].
func (*OptionsMonitor[T]) CurrentValue ¶
func (m *OptionsMonitor[T]) CurrentValue() *T
CurrentValue returns the current configured value.
func (*OptionsMonitor[T]) Get ¶
func (m *OptionsMonitor[T]) Get(name string) *T
Get returns the configured value for the specified name.
func (*OptionsMonitor[T]) OnChange ¶
func (m *OptionsMonitor[T]) OnChange(listener func(*T, string))
OnChange registers a listener to be called whenever the configuration changes.
func (*OptionsMonitor[T]) Set ¶
func (m *OptionsMonitor[T]) Set(value *T)
Set updates the configured value and notifies listeners.
type XmlConfigurationProvider ¶
type XmlConfigurationProvider struct {
*ConfigurationProvider
// contains filtered or unexported fields
}
XmlConfigurationProvider is a provider for XML configuration files.
func (*XmlConfigurationProvider) Load ¶
func (p *XmlConfigurationProvider) Load() map[string]string
Load loads configuration from XML file.
type XmlConfigurationSource ¶
XmlConfigurationSource represents an XML file configuration source.
func (*XmlConfigurationSource) Build ¶
func (s *XmlConfigurationSource) Build(builder IConfigurationBuilder) IConfigurationProvider
Build builds an IConfigurationProvider from the XML source.
type YamlConfigurationProvider ¶
type YamlConfigurationProvider struct {
*ConfigurationProvider
// contains filtered or unexported fields
}
YamlConfigurationProvider is a provider for YAML configuration files.
func (*YamlConfigurationProvider) Load ¶
func (p *YamlConfigurationProvider) Load() map[string]string
Load loads configuration from YAML file.
type YamlConfigurationSource ¶
YamlConfigurationSource represents a YAML file configuration source.
func (*YamlConfigurationSource) Build ¶
func (s *YamlConfigurationSource) Build(builder IConfigurationBuilder) IConfigurationProvider
Build builds an IConfigurationProvider from the YAML source.