ai-code-battle/cmd/acb-api/server.go
jedarden 4aca8add20 Add Discord/Slack alerting webhooks to Go API server
Implements the monitoring alerting deliverable from Phase 6. The Alerter
module sends color-coded notifications to Discord and/or Slack webhooks
for operational events: bot health transitions, stale job re-enqueues,
and match errors. Includes per-key rate limiting to prevent alert storms.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-26 01:32:47 -04:00

36 lines
945 B
Go

package main
import (
"database/sql"
"encoding/json"
"net/http"
"github.com/redis/go-redis/v9"
)
type Server struct {
cfg Config
db *sql.DB
rdb *redis.Client
alerter *Alerter
}
func (s *Server) RegisterRoutes(mux *http.ServeMux) {
mux.HandleFunc("GET /health", s.handleHealth)
mux.HandleFunc("GET /ready", s.handleReady)
mux.HandleFunc("POST /api/register", s.handleRegister)
mux.HandleFunc("POST /api/rotate-key", s.handleRotateKey)
mux.HandleFunc("GET /api/status/{bot_id}", s.handleBotStatus)
mux.HandleFunc("POST /api/jobs/claim", s.handleJobClaim)
mux.HandleFunc("POST /api/jobs/{job_id}/result", s.handleJobResult)
}
func writeJSON(w http.ResponseWriter, status int, v any) {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(status)
json.NewEncoder(w).Encode(v)
}
func writeError(w http.ResponseWriter, status int, msg string) {
writeJSON(w, status, map[string]string{"error": msg})
}