Files
pipeline_backend/watcher/internal/config/config.go
2026-06-24 18:58:35 +03:00

63 lines
1.4 KiB
Go

package config
import (
"os"
"strconv"
"time"
)
type Config struct {
StorageRoot string
IncomingDir string
ProcessingDir string
FailedDir string
PollInterval time.Duration
StableWindow time.Duration
StableChecks int
RabbitURL string
Exchange string
RoutingKey string
StatusQueue string
}
func Load() Config {
return Config{
StorageRoot: getEnv("STORAGE_ROOT", "/data/storage"),
IncomingDir: getEnv("INCOMING_DIR", "incoming"),
ProcessingDir: getEnv("PROCESSING_DIR", "processing"),
FailedDir: getEnv("FAILED_DIR", "failed"),
PollInterval: getDuration("POLL_INTERVAL", 5*time.Second),
StableWindow: getDuration("STABLE_WINDOW", 2*time.Second),
StableChecks: getInt("STABLE_CHECKS", 3),
RabbitURL: getEnv("RABBITMQ_URL", "amqp://guest:guest@localhost:5672/"),
Exchange: getEnv("RABBITMQ_EXCHANGE", "audio_pipeline"),
RoutingKey: getEnv("RABBITMQ_ROUTING_KEY", "audio.new"),
StatusQueue: getEnv("STATUS_QUEUE", "pipeline.status"),
}
}
func getEnv(key, def string) string {
if v := os.Getenv(key); v != "" {
return v
}
return def
}
func getInt(key string, def int) int {
if v := os.Getenv(key); v != "" {
if i, err := strconv.Atoi(v); err == nil {
return i
}
}
return def
}
func getDuration(key string, def time.Duration) time.Duration {
if v := os.Getenv(key); v != "" {
if d, err := time.ParseDuration(v); err == nil {
return d
}
}
return def
}