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:
@@ -25,6 +25,17 @@ type Config struct {
|
||||
Servers []Server `yaml:"servers"`
|
||||
Aggregate *AggregateConfig `yaml:"aggregate"`
|
||||
GeoIP *GeoIPConfig `yaml:"geoip"`
|
||||
Radar *RadarConfig `yaml:"radar"`
|
||||
}
|
||||
|
||||
// RadarConfig controls GET /api/radar/statuses and /api/radar/ping-dc (Telegram DC radar).
|
||||
type RadarConfig struct {
|
||||
// StatusesURL defaults to https://radar.telemt.top/api/v1/endpoints/statuses when empty.
|
||||
StatusesURL string `yaml:"statuses_url"`
|
||||
// HTTPTimeoutMs is outbound GET timeout for statuses; 0 means 30000.
|
||||
HTTPTimeoutMs uint64 `yaml:"http_timeout_ms"`
|
||||
// PingFrom is copied into JSON field "from" in ping-dc; empty uses request Host (no port) or "telemt-gateway".
|
||||
PingFrom string `yaml:"ping_from"`
|
||||
}
|
||||
|
||||
// GeoIPConfig enables GeoLite2 lookups for /api/agg/unique-ips (optional).
|
||||
@@ -162,6 +173,17 @@ func (c *Config) Validate() error {
|
||||
return fmt.Errorf("aggregate.cache_ttl_ms must be within [0, 60000]")
|
||||
}
|
||||
}
|
||||
if c.Radar != nil {
|
||||
if c.Radar.HTTPTimeoutMs > 600000 {
|
||||
return fmt.Errorf("radar.http_timeout_ms must be within [0, 600000]")
|
||||
}
|
||||
if u := strings.TrimSpace(c.Radar.StatusesURL); u != "" {
|
||||
pu, err := url.Parse(u)
|
||||
if err != nil || (pu.Scheme != "http" && pu.Scheme != "https") || pu.Host == "" {
|
||||
return fmt.Errorf("radar.statuses_url: invalid URL %q", c.Radar.StatusesURL)
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -114,3 +114,27 @@ func TestValidateAggregateCacheTTL(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateRadarStatusesURL(t *testing.T) {
|
||||
c := &Config{
|
||||
Servers: []Server{{Alias: "a", BaseURL: "http://x:1"}},
|
||||
Radar: &RadarConfig{StatusesURL: "ftp://bad"},
|
||||
}
|
||||
if err := c.Validate(); err == nil {
|
||||
t.Fatal("expected error for invalid radar.statuses_url scheme")
|
||||
}
|
||||
c.Radar.StatusesURL = "https://radar.example/api"
|
||||
if err := c.Validate(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateRadarHTTPTimeoutMs(t *testing.T) {
|
||||
c := &Config{
|
||||
Servers: []Server{{Alias: "a", BaseURL: "http://x:1"}},
|
||||
Radar: &RadarConfig{HTTPTimeoutMs: 600001},
|
||||
}
|
||||
if err := c.Validate(); err == nil {
|
||||
t.Fatal("expected error for radar.http_timeout_ms > 600000")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user