working mode
This commit is contained in:
@@ -37,16 +37,40 @@ var DefaultConfig = Config{
|
||||
func LoadConfig() (*Config, error) {
|
||||
config := DefaultConfig
|
||||
|
||||
// Try to load .env file from current directory or parent directories
|
||||
envFile := findEnvFile()
|
||||
if envFile != "" {
|
||||
if err := godotenv.Load(envFile); err != nil {
|
||||
logging.Warning("Could not load .env file from %s: %v", envFile, err)
|
||||
// Priority order for loading configuration:
|
||||
// 1. /etc/nannyagent/config.env (system-wide installation)
|
||||
// 2. Current directory .env file (development)
|
||||
// 3. Parent directory .env file (development)
|
||||
|
||||
configLoaded := false
|
||||
|
||||
// Try system-wide config first
|
||||
if _, err := os.Stat("/etc/nannyagent/config.env"); err == nil {
|
||||
if err := godotenv.Load("/etc/nannyagent/config.env"); err != nil {
|
||||
logging.Warning("Could not load /etc/nannyagent/config.env: %v", err)
|
||||
} else {
|
||||
logging.Info("Loaded configuration from %s", envFile)
|
||||
logging.Info("Loaded configuration from /etc/nannyagent/config.env")
|
||||
configLoaded = true
|
||||
}
|
||||
}
|
||||
|
||||
// If system config not found, try local .env file
|
||||
if !configLoaded {
|
||||
envFile := findEnvFile()
|
||||
if envFile != "" {
|
||||
if err := godotenv.Load(envFile); err != nil {
|
||||
logging.Warning("Could not load .env file from %s: %v", envFile, err)
|
||||
} else {
|
||||
logging.Info("Loaded configuration from %s", envFile)
|
||||
configLoaded = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if !configLoaded {
|
||||
logging.Warning("No configuration file found. Using environment variables only.")
|
||||
}
|
||||
|
||||
// Load from environment variables
|
||||
if url := os.Getenv("SUPABASE_PROJECT_URL"); url != "" {
|
||||
config.SupabaseProjectURL = url
|
||||
|
||||
Reference in New Issue
Block a user