audio_pipeline
This commit is contained in:
60
watcher/internal/config/config.go
Normal file
60
watcher/internal/config/config.go
Normal file
@@ -0,0 +1,60 @@
|
||||
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
|
||||
}
|
||||
|
||||
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"),
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user