Documentation
¶
Index ¶
- func LoadGlobalConfig(path string, target any) error
- func LoadProjectConfig(mainPath string, overridePaths []string, target any) error
- func LoadProjectConfigFromContents(mainContent []byte, overrides []OverrideConfig, target any) error
- func RecursiveMerge(dst, src map[string]any, replaceSlices bool) error
- type ConfigProvider
- type OverrideConfig
- type ProviderFactory
- type ViperFactory
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func LoadGlobalConfig ¶
LoadGlobalConfig loads a single global configuration file into the target struct. It is intentionally kept separate from LoadProjectConfig to remain fast and lightweight, as it does not need to support the heavy lifting of RecursiveMerge that project configurations require for deep map and slice overrides.
func LoadProjectConfig ¶
LoadProjectConfig loads a main project config and merges optional overrides into the target struct.
func LoadProjectConfigFromContents ¶
func LoadProjectConfigFromContents(mainContent []byte, overrides []OverrideConfig, target any) error
LoadProjectConfigFromContents loads a main project config and merges optional overrides from pre-read bytes.
Types ¶
type ConfigProvider ¶
type ConfigProvider interface {
GetString(key string) string
GetInt(key string) int
GetBool(key string) bool
SetDefault(key string, value any)
Set(key string, value any)
Unmarshal(rawVal any) error
Unset(key string)
ReadConfig(path string) error
ReadConfigFromBytes(data []byte) error
MergeConfig(path string) error
}
ConfigProvider defines the interface for configuration providers.
func NewConfigProvider ¶
func NewConfigProvider() ConfigProvider
NewConfigProvider returns a new ConfigProvider from the default factory.
type OverrideConfig ¶
OverrideConfig represents a configuration override with its source path and contents.
type ProviderFactory ¶
type ProviderFactory interface {
CreateConfigProvider() ConfigProvider
LoadProjectConfig(mainPath string, overridePaths []string, target any) error
LoadProjectConfigFromContents(mainContent []byte, overrides []OverrideConfig, target any) error
}
ProviderFactory defines the interface for creating ConfigProviders.
type ViperFactory ¶
type ViperFactory struct{}
ViperFactory implements ProviderFactory using Viper.
func (*ViperFactory) CreateConfigProvider ¶
func (vf *ViperFactory) CreateConfigProvider() ConfigProvider
CreateConfigProvider returns a new isolated ConfigProvider.
func (*ViperFactory) LoadProjectConfig ¶
func (vf *ViperFactory) LoadProjectConfig(mainPath string, overridePaths []string, target any) error
LoadProjectConfig loads a main project config and merges optional overrides into the target struct.
func (*ViperFactory) LoadProjectConfigFromContents ¶
func (vf *ViperFactory) LoadProjectConfigFromContents(mainContent []byte, overrides []OverrideConfig, target any) error
LoadProjectConfigFromContents loads a main project config and merges optional overrides from pre-read bytes.