drive-health/lib/config/config.go

49 lines
1.1 KiB
Go
Raw Normal View History

package config
2024-01-20 02:06:27 +02:00
import (
"log"
"os"
"strconv"
"github.com/joho/godotenv"
)
type DHConfig struct {
2024-01-20 02:06:27 +02:00
DiskFetchFrequency int `json:"diskFetchFrequency"`
MemoryDumpFrequency int `json:"memoryDumpFrequency"`
MaxHistoryAge int `json:"maxHistoryAge"`
}
func GetConfiguration() DHConfig {
2024-01-20 02:06:27 +02:00
// Load .env file if it exists
if err := godotenv.Load(); err != nil {
log.Println("No .env file found")
}
config := DHConfig{
DiskFetchFrequency: 5, // default value
MemoryDumpFrequency: 60, // default value
MaxHistoryAge: 2592000, // default value
}
if val, exists := os.LookupEnv("DISK_FETCH_FREQUENCY"); exists {
if intValue, err := strconv.Atoi(val); err == nil {
config.DiskFetchFrequency = intValue
}
}
2024-01-20 02:06:27 +02:00
if val, exists := os.LookupEnv("MEMORY_DUMP_FREQUENCY"); exists {
if intValue, err := strconv.Atoi(val); err == nil {
config.MemoryDumpFrequency = intValue
}
}
2024-01-20 02:06:27 +02:00
if val, exists := os.LookupEnv("MAX_HISTORY_AGE"); exists {
if intValue, err := strconv.Atoi(val); err == nil {
config.MaxHistoryAge = intValue
}
}
2024-01-20 02:06:27 +02:00
return config
}