two/cmd/agent/main.go
GnomeZworc 63a288f69e
f-21: refactor: add dispatcher layer for MQTT migration
Introduce internal/dispatcher package with a Command interface and typed
commands (CreateVPC, DeleteVPC, CreateSubnet, DeleteSubnet). The API
handlers now call dispatcher.Dispatch() instead of enqueuing closures
directly, decoupling transport (HTTP today, MQTT tomorrow) from execution.

Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
2026-04-21 23:36:33 +02:00

44 lines
1.2 KiB
Go

package main
import (
"flag"
"fmt"
"log"
agentapi "git.g3e.fr/syonad/two/internal/api/agent"
configuration "git.g3e.fr/syonad/two/internal/config/agent"
"git.g3e.fr/syonad/two/internal/dispatcher"
agentmetrics "git.g3e.fr/syonad/two/internal/prometheus/agent"
"git.g3e.fr/syonad/two/pkg/db/kv"
promserver "git.g3e.fr/syonad/two/pkg/prometheus"
"git.g3e.fr/syonad/two/pkg/worker"
"github.com/prometheus/client_golang/prometheus"
)
func main() {
confFile := flag.String("config", "/etc/two/agent.yml", "config file path")
flag.Parse()
cfg, err := configuration.LoadConfig(*confFile)
if err != nil {
log.Fatalf("failed to load config: %v", err)
}
db := kv.InitDB(kv.Config{Path: cfg.Database.Path}, false)
defer db.Close()
q := worker.New(cfg.Worker.BufferSize)
q.Start(cfg.Worker.Count)
registry := prometheus.NewRegistry()
registry.MustRegister(agentmetrics.NewAgentCollector(db))
apiAddr := fmt.Sprintf("%s:%d", cfg.Api.Address, cfg.Api.Port)
promAddr := fmt.Sprintf("%s:%d", cfg.Prometheus.Address, cfg.Prometheus.Port)
d := dispatcher.New(q, db)
go agentapi.New(d, db).Start(apiAddr)
go promserver.Start(promAddr, registry)
select {}
}