2aa0c3be86
Initialise le module Go github.com/user/nanometrics/server avec toutes les dépendances (SQLite, gorilla/websocket, paho.mqtt, prometheus, imaging). Ajoute config.go (Load/Default via env vars) et models.go (AgentMetrics, SmartMetrics, Agent, AgentConfig, ServerConfig, WSMessage). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
39 lines
839 B
Go
39 lines
839 B
Go
package config
|
|
|
|
import "os"
|
|
|
|
type Config struct {
|
|
UDPAddr string
|
|
DBPath string
|
|
HTTPAddr string
|
|
MQTTBroker string
|
|
MQTTTopicBase string
|
|
}
|
|
|
|
func Load() Config {
|
|
return Config{
|
|
UDPAddr: getEnv("UDP_ADDR", "0.0.0.0:9999"),
|
|
DBPath: getEnv("DB_PATH", "/data/nanometrics.db"),
|
|
HTTPAddr: getEnv("HTTP_ADDR", "0.0.0.0:8080"),
|
|
MQTTBroker: getEnv("MQTT_BROKER", "tcp://10.0.0.3:1883"),
|
|
MQTTTopicBase: getEnv("MQTT_TOPIC_BASE", "nanometrics/agents"),
|
|
}
|
|
}
|
|
|
|
func getEnv(key, fallback string) string {
|
|
if v := os.Getenv(key); v != "" {
|
|
return v
|
|
}
|
|
return fallback
|
|
}
|
|
|
|
func Default() Config {
|
|
return Config{
|
|
UDPAddr: "127.0.0.1:19999",
|
|
DBPath: ":memory:",
|
|
HTTPAddr: "127.0.0.1:18080",
|
|
MQTTBroker: "tcp://127.0.0.1:11883",
|
|
MQTTTopicBase: "test/nanometrics",
|
|
}
|
|
}
|