Add Radar DC Telegram functionality and configuration
- 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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user