chore: auto-commit (3 archivos)

- app.md
- handlers.go
- events.go

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Egutierrez
2026-05-14 00:28:22 +02:00
parent af13fd849c
commit a1769a3976
3 changed files with 425 additions and 5 deletions
+13 -4
View File
@@ -7,6 +7,8 @@ import (
"net/http"
"strings"
"time"
"fn-registry/functions/infra"
)
const queryTimeout = 5 * time.Second
@@ -15,10 +17,15 @@ const queryTimeout = 5 * time.Second
type Server struct {
pool *DBPool
registryRoot string // raiz del fn_registry (para exec fn ...)
hub *CallMonitorHub
}
func NewServer(pool *DBPool, registryRoot string) *Server {
return &Server{pool: pool, registryRoot: registryRoot}
return &Server{
pool: pool,
registryRoot: registryRoot,
hub: NewCallMonitorHub(pool),
}
}
// Routes registers all API routes on the given mux.
@@ -39,6 +46,10 @@ func (s *Server) Routes(mux *http.ServeMux) {
mux.HandleFunc("POST /api/add/app", s.handleAddApp)
mux.HandleFunc("POST /api/add/analysis", s.handleAddAnalysis)
mux.HandleFunc("POST /api/add/vault", s.handleAddVault)
// Issue 0086: WebSocket live stream de ops:call_monitor (calls table).
// Hub global con ticker bajo demanda (solo corre con >=1 subscriber).
mux.HandleFunc("GET /api/events/call_monitor", s.handleEvents(s.hub))
}
func (s *Server) handleHealth(w http.ResponseWriter, r *http.Request) {
@@ -315,9 +326,7 @@ func corsMiddleware(next http.Handler) http.Handler {
}
func writeJSON(w http.ResponseWriter, status int, data any) {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(status)
json.NewEncoder(w).Encode(data)
infra.HTTPJSONResponse(w, status, data)
}
func writeError(w http.ResponseWriter, status int, msg string) {