43 lines
911 B
Go
43 lines
911 B
Go
package config
|
|
|
|
import (
|
|
"os"
|
|
"strconv"
|
|
|
|
"github.com/joho/godotenv"
|
|
)
|
|
|
|
// Config holds runtime configuration
|
|
type Config struct {
|
|
S3Bucket string `json:"s3Bucket"`
|
|
LocalDest string `json:"localDest"`
|
|
AWSProfile string `json:"awsProfile"`
|
|
Concurrency int `json:"concurrency"`
|
|
}
|
|
|
|
// Load reads config from ENV (with optional .env file)
|
|
func Load(envFile string) Config {
|
|
_ = godotenv.Load(envFile) // ignore if missing
|
|
|
|
concurrency := 4
|
|
if v := os.Getenv("FIELD_SYNC_CONCURRENCY"); v != "" {
|
|
if n, err := strconv.Atoi(v); err == nil && n > 0 {
|
|
concurrency = n
|
|
}
|
|
}
|
|
|
|
return Config{
|
|
S3Bucket: getenv("FIELD_SYNC_S3_BUCKET", ""),
|
|
LocalDest: getenv("FIELD_SYNC_LOCAL_DEST", os.TempDir()),
|
|
AWSProfile: getenv("AWS_PROFILE", "cosma"),
|
|
Concurrency: concurrency,
|
|
}
|
|
}
|
|
|
|
func getenv(key, fallback string) string {
|
|
if v := os.Getenv(key); v != "" {
|
|
return v
|
|
}
|
|
return fallback
|
|
}
|