updated ezconf
This commit is contained in:
@@ -6,16 +6,14 @@ import (
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
User string // ENV DB_USER: Database user for authentication (required)
|
||||
Password string // ENV DB_PASSWORD: Database password for authentication (required)
|
||||
Host string // ENV DB_HOST: Database host address (required)
|
||||
Port uint16 // ENV DB_PORT: Database port (default: 5432)
|
||||
DB string // ENV DB_NAME: Database name to connect to (required)
|
||||
SSL string // ENV DB_SSL: SSL mode for connection (default: disable)
|
||||
|
||||
// Backup configuration
|
||||
BackupDir string // ENV DB_BACKUP_DIR: Directory for database backups (default: backups)
|
||||
BackupRetention int // ENV DB_BACKUP_RETENTION: Number of backups to keep (default: 10)
|
||||
User string `ezconf:"DB_USER,required,description:Database user for authentication"`
|
||||
Password string `ezconf:"DB_PASSWORD,required,description:Database password for authentication"`
|
||||
Host string `ezconf:"DB_HOST,required,description:Database host address"`
|
||||
Port uint16 `ezconf:"DB_PORT,default:5432,description:Database port"`
|
||||
DB string `ezconf:"DB_NAME,required,description:Database to connect to"`
|
||||
SSL string `ezconf:"DB_SSL,default:disable,description:SSL Mode"`
|
||||
BackupDir string `ezconf:"DB_BACKUP_DIR,default:backups,description:Directory for database backups"`
|
||||
BackupRetention int `ezconf:"DB_BACKUP_RETENTION,default:10,description:Number of backups to keep"`
|
||||
}
|
||||
|
||||
func ConfigFromEnv() (any, error) {
|
||||
|
||||
@@ -1,41 +1,11 @@
|
||||
package db
|
||||
|
||||
import (
|
||||
"runtime"
|
||||
"strings"
|
||||
"git.haelnorr.com/h/golib/ezconf"
|
||||
)
|
||||
|
||||
// EZConfIntegration provides integration with ezconf for automatic configuration
|
||||
type EZConfIntegration struct {
|
||||
configFunc func() (any, error)
|
||||
name string
|
||||
}
|
||||
|
||||
// PackagePath returns the path to the config package for source parsing
|
||||
func (e EZConfIntegration) PackagePath() string {
|
||||
_, filename, _, _ := runtime.Caller(0)
|
||||
// Return directory of this file
|
||||
return filename[:len(filename)-len("/ezconf.go")]
|
||||
}
|
||||
|
||||
// ConfigFunc returns the ConfigFromEnv function for ezconf
|
||||
func (e EZConfIntegration) ConfigFunc() func() (any, error) {
|
||||
return func() (any, error) {
|
||||
return e.configFunc()
|
||||
}
|
||||
}
|
||||
|
||||
// Name returns the name to use when registering with ezconf
|
||||
func (e EZConfIntegration) Name() string {
|
||||
return strings.ToLower(e.name)
|
||||
}
|
||||
|
||||
// GroupName returns the display name for grouping environment variables
|
||||
func (e EZConfIntegration) GroupName() string {
|
||||
return e.name
|
||||
}
|
||||
|
||||
// NewEZConfIntegration creates a new EZConf integration helper
|
||||
func NewEZConfIntegration() EZConfIntegration {
|
||||
return EZConfIntegration{name: "DB", configFunc: ConfigFromEnv}
|
||||
func NewEZConfIntegration() *ezconf.Integration {
|
||||
return ezconf.NewIntegration("db", "DB", &Config{},
|
||||
func() (any, error) { return ConfigFromEnv() })
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user