feat(server): go.mod + config + modèles de données
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>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
331415bbab
commit
2aa0c3be86
@@ -0,0 +1,38 @@
|
||||
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",
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user