feat: initial open-source release of Pipely
OTA update server designed for high-concurrency, low-bandwidth deployments. GORM-backed PostgreSQL, JWT auth, device management, artefact versioning, deployment rollout with gated rate-limited downloads, and a React admin panel.
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"log"
|
||||
"os"
|
||||
"strconv"
|
||||
|
||||
"github.com/joho/godotenv"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
ServerPort string
|
||||
JWTSecret string
|
||||
JWTExpiryHrs int
|
||||
DatabaseURL string
|
||||
ArtefactDir string
|
||||
MaxConcurrent int
|
||||
BandwidthBPS int
|
||||
RateLimitRPS int
|
||||
}
|
||||
|
||||
func Load() *Config {
|
||||
// Load .env file if present (silently ignore if not found)
|
||||
if err := godotenv.Load(); err != nil {
|
||||
log.Println("[config] No .env file found, using system environment variables")
|
||||
}
|
||||
|
||||
return &Config{
|
||||
ServerPort: envOrDefault("SERVER_PORT", "8080"),
|
||||
JWTSecret: envOrDefault("JWT_SECRET", "change-me-in-production"),
|
||||
JWTExpiryHrs: envOrDefaultInt("JWT_EXPIRY_HRS", 24),
|
||||
DatabaseURL: envOrDefault("DATABASE_URL", "postgres://postgres:postgres@localhost:5432/manifest?sslmode=disable"),
|
||||
ArtefactDir: envOrDefault("ARTEFACT_DIR", "/var/ota/artefacts"),
|
||||
MaxConcurrent: envOrDefaultInt("MAX_CONCURRENT_DOWNLOADS", 50),
|
||||
BandwidthBPS: envOrDefaultInt("BANDWIDTH_BPS", 10*1024*1024/50),
|
||||
RateLimitRPS: envOrDefaultInt("RATE_LIMIT_RPS", 100),
|
||||
}
|
||||
}
|
||||
|
||||
func envOrDefault(key, def string) string {
|
||||
if v := os.Getenv(key); v != "" {
|
||||
return v
|
||||
}
|
||||
return def
|
||||
}
|
||||
|
||||
func envOrDefaultInt(key string, def int) int {
|
||||
if v := os.Getenv(key); v != "" {
|
||||
if n, err := strconv.Atoi(v); err == nil {
|
||||
return n
|
||||
}
|
||||
}
|
||||
return def
|
||||
}
|
||||
Reference in New Issue
Block a user