Files
spore-registry/internal/config/config.go
2025-10-21 22:43:18 +02:00

48 lines
833 B
Go

package config
import (
"os"
"strconv"
)
// Config holds the application configuration
type Config struct {
Port string
DBPath string
Registry string
MaxSize int64
}
// LoadConfig loads configuration from environment variables with defaults
func LoadConfig() *Config {
port := os.Getenv("PORT")
if port == "" {
port = "3002"
}
dbPath := os.Getenv("DB_PATH")
if dbPath == "" {
dbPath = "./registry.db"
}
registry := os.Getenv("REGISTRY_PATH")
if registry == "" {
registry = "registry"
}
maxSizeStr := os.Getenv("MAX_UPLOAD_SIZE")
maxSize := int64(32 << 20) // 32MB default
if maxSizeStr != "" {
if parsed, err := strconv.ParseInt(maxSizeStr, 10, 64); err == nil {
maxSize = parsed
}
}
return &Config{
Port: port,
DBPath: dbPath,
Registry: registry,
MaxSize: maxSize,
}
}