Add Radar DC Telegram functionality and configuration
Publish telemt-api gateway Docker image / test (push) Successful in 23s
Publish telemt-api gateway Docker image / build-and-push (push) Successful in 2m9s

- Introduced new `RadarConfig` structure in `config.go` to manage radar settings, including `statuses_url`, `http_timeout_ms`, and `ping_from`.
- Implemented validation for radar configuration in `config_test.go` to ensure correct URL schemes and timeout limits.
- Added new API routes for radar statuses and ping functionality in the gateway, enhancing the service's capabilities.
- Updated documentation in `GATEWAY_RUN.md` to include details about the new radar features and their usage.
- Enhanced the user interface to include navigation and display options for the Radar DC section in the sidebar and page titles.
- Added client-side API functions for fetching radar statuses and ping responses, improving integration with the frontend.
This commit is contained in:
Denozordec
2026-04-12 12:53:20 +07:00
parent 6b2e38d051
commit d021e4b1d7
15 changed files with 723 additions and 1 deletions
+29
View File
@@ -34,6 +34,9 @@ type Gateway struct {
promHandler http.Handler
corsAllowed []string
webUI http.Handler
radarStatusesURL string
radarPingFrom string
radarHTTPClient *http.Client
}
func writeBadGatewayJSON(w http.ResponseWriter, expose bool, code, message string, upstreamErr error) {
@@ -96,6 +99,21 @@ func NewGateway(p *config.Parsed, log *slog.Logger, geo *geoip.Service) (*Gatewa
g.corsAllowed = append([]string(nil), p.Config.CorsAllowedOrigins...)
g.agg = aggregate.NewHandler(p, &http.Client{Transport: t}, geo, aggCacheTTL)
g.webUI = webui.Handler()
statusesURL := defaultRadarStatusesURL
radarTo := 30 * time.Second
if p.Config.Radar != nil {
if u := strings.TrimSpace(p.Config.Radar.StatusesURL); u != "" {
statusesURL = u
}
if p.Config.Radar.HTTPTimeoutMs > 0 {
radarTo = time.Duration(p.Config.Radar.HTTPTimeoutMs) * time.Millisecond
}
g.radarPingFrom = strings.TrimSpace(p.Config.Radar.PingFrom)
}
g.radarStatusesURL = statusesURL
g.radarHTTPClient = &http.Client{Transport: t, Timeout: radarTo}
return g, nil
}
@@ -242,6 +260,13 @@ func routeEndpoint(path string) string {
if path == "/api/agg" {
return "agg"
}
if strings.HasPrefix(path, "/api/radar/") {
rest := strings.TrimPrefix(path, "/api/radar/")
if rest == "" {
return "radar"
}
return "radar_" + strings.ReplaceAll(rest, "/", "_")
}
if strings.HasPrefix(path, "/api/live/events") {
return "live_events"
}
@@ -291,6 +316,10 @@ func (g *Gateway) serve(w http.ResponseWriter, r *http.Request) {
g.serveLiveEvents(w, r)
return
}
if r.URL.Path == "/api/radar/statuses" || r.URL.Path == "/api/radar/ping-dc" {
g.serveRadar(w, r)
return
}
if !strings.HasPrefix(r.URL.Path, prefix) {
g.webUI.ServeHTTP(w, r)
return