added ezconf and updated modules with integration

This commit is contained in:
2026-01-13 21:18:35 +11:00
parent f8919e8398
commit 0ceeb37058
22 changed files with 2448 additions and 3 deletions

46
ezconf/integration.go Normal file
View File

@@ -0,0 +1,46 @@
package ezconf
// Integration is an interface that packages can implement to provide
// easy integration with ezconf
type Integration interface {
// Name returns the name to use when registering the config
Name() string
// PackagePath returns the path to the package for source parsing
PackagePath() string
// ConfigFunc returns the ConfigFromEnv function
ConfigFunc() func() (interface{}, error)
// GroupName returns the display name for grouping environment variables
GroupName() string
}
// RegisterIntegration registers a package that implements the Integration interface
func (cl *ConfigLoader) RegisterIntegration(integration Integration) error {
// Add package path
pkgPath := integration.PackagePath()
if err := cl.AddPackagePath(pkgPath); err != nil {
return err
}
// Store group name for this package
cl.groupNames[pkgPath] = integration.GroupName()
// Add config function
if err := cl.AddConfigFunc(integration.Name(), integration.ConfigFunc()); err != nil {
return err
}
return nil
}
// RegisterIntegrations registers multiple integrations at once
func (cl *ConfigLoader) RegisterIntegrations(integrations ...Integration) error {
for _, integration := range integrations {
if err := cl.RegisterIntegration(integration); err != nil {
return err
}
}
return nil
}