package config import ( "os" "time" ) type Config struct { Addr string DBPath string ArchiveAfter time.Duration // StaleAfter is how long a firing alert may go without a refreshing webhook // before the sweeper treats it as resolved. It must exceed Alertmanager's // repeat_interval (default 4h), which is what refreshes the alert. StaleAfter time.Duration } func Load() Config { addr := os.Getenv("TERDUT_ADDR") if addr == "" { addr = ":8080" } dbPath := os.Getenv("TERDUT_DB_PATH") if dbPath == "" { dbPath = "terdut.db" } archiveAfter := 7 * 24 * time.Hour if s := os.Getenv("TERDUT_ARCHIVE_AFTER"); s != "" { if d, err := time.ParseDuration(s); err == nil { archiveAfter = d } } staleAfter := 6 * time.Hour if s := os.Getenv("TERDUT_STALE_AFTER"); s != "" { if d, err := time.ParseDuration(s); err == nil { staleAfter = d } } return Config{Addr: addr, DBPath: dbPath, ArchiveAfter: archiveAfter, StaleAfter: staleAfter} }