move feature from meta-sort to meta-core

This commit is contained in:
Pierre
2026-01-25 22:01:25 +01:00
parent 768942d28b
commit 7d9d502912
69 changed files with 12831 additions and 13 deletions
+56 -1
View File
@@ -3,6 +3,7 @@ package config
import (
"os"
"strconv"
"strings"
)
// Config holds all configuration for meta-core
@@ -28,11 +29,20 @@ type Config struct {
HealthCheckIntervalMS int // Health check interval in ms (default: 5000)
HeartbeatIntervalMS int // Service heartbeat interval in ms (default: 30000)
StaleThresholdMS int // Stale service threshold in ms (default: 60000)
// File watcher configuration
WatchFolderList []string // List of folders to watch for file changes
WatchIntervalMS int // Polling interval for network mounts (default: 1000)
DebounceMS int // File change debounce time (default: 30000)
EnableFileWatcher bool // Enable file watcher (default: true)
// Mount configuration
MountsDir string // Path to mounts configuration (default: /meta-core/mounts)
}
// Load creates a Config from environment variables
func Load() *Config {
return &Config{
cfg := &Config{
MetaCorePath: getEnv("META_CORE_PATH", "/meta-core"),
FilesPath: getEnv("FILES_PATH", "/files"),
ServiceName: getEnv("SERVICE_NAME", "meta-core"),
@@ -45,7 +55,19 @@ func Load() *Config {
HealthCheckIntervalMS: getEnvInt("HEALTH_CHECK_INTERVAL_MS", 5000),
HeartbeatIntervalMS: getEnvInt("HEARTBEAT_INTERVAL_MS", 30000),
StaleThresholdMS: getEnvInt("STALE_THRESHOLD_MS", 60000),
WatchIntervalMS: getEnvInt("WATCH_INTERVAL_MS", 1000),
DebounceMS: getEnvInt("DEBOUNCE_MS", 30000),
EnableFileWatcher: getEnvBool("ENABLE_FILE_WATCHER", true),
}
// Parse watch folder list (comma-separated)
watchFolders := getEnv("WATCH_FOLDER_LIST", "/files/")
cfg.WatchFolderList = parseCommaSeparated(watchFolders)
// Set mounts directory
cfg.MountsDir = cfg.MetaCorePath + "/mounts"
return cfg
}
// LockFilePath returns the path to the leader lock file
@@ -68,6 +90,16 @@ func (c *Config) ServicesDir() string {
return c.MetaCorePath + "/services"
}
// MountsFilePath returns the path to the mounts configuration file
func (c *Config) MountsFilePath() string {
return c.MountsDir + "/mounts.json"
}
// MountsErrorDir returns the path to mount error files
func (c *Config) MountsErrorDir() string {
return c.MountsDir + "/errors"
}
func getEnv(key, defaultValue string) string {
if value := os.Getenv(key); value != "" {
return value
@@ -83,3 +115,26 @@ func getEnvInt(key string, defaultValue int) int {
}
return defaultValue
}
func getEnvBool(key string, defaultValue bool) bool {
if value := os.Getenv(key); value != "" {
lower := strings.ToLower(value)
return lower == "true" || lower == "1" || lower == "yes"
}
return defaultValue
}
func parseCommaSeparated(s string) []string {
if s == "" {
return []string{}
}
parts := strings.Split(s, ",")
result := make([]string, 0, len(parts))
for _, part := range parts {
trimmed := strings.TrimSpace(part)
if trimmed != "" {
result = append(result, trimmed)
}
}
return result
}