This commit is contained in:
Kar
2026-02-01 20:38:58 +05:30
parent 52265ed4cc
commit 5e563fb436
11 changed files with 159 additions and 51 deletions

54
internal/config/config.go Normal file
View File

@@ -0,0 +1,54 @@
package config
import (
"os"
"strconv"
"time"
)
type Config struct {
DBPath string
MaxWorkers int
ReconcileTick time.Duration
HTTPPort string
Kubeconfig string
Namespace string
}
func Load() *Config {
cfg := &Config{
DBPath: getEnv("DB_PATH", "./manager.db"),
MaxWorkers: getEnvInt("MAX_WORKERS", 2),
ReconcileTick: getEnvDuration("RECONCILE_TICK", 2*time.Second),
HTTPPort: getEnv("HTTP_PORT", "8080"),
Kubeconfig: getEnv("KUBECONFIG", ".env/cluster1.yaml"),
Namespace: getEnv("NAMESPACE", "default"),
}
return cfg
}
func getEnv(key, defaultValue string) string {
if value := os.Getenv(key); value != "" {
return value
}
return defaultValue
}
func getEnvInt(key string, defaultValue int) int {
if value := os.Getenv(key); value != "" {
if intValue, err := strconv.Atoi(value); err == nil {
return intValue
}
}
return defaultValue
}
func getEnvDuration(key string, defaultValue time.Duration) time.Duration {
if value := os.Getenv(key); value != "" {
if intValue, err := strconv.Atoi(value); err == nil {
return time.Duration(intValue) * time.Second
}
}
return defaultValue
}