Updates in preparation for adding forecast sources.
This commit is contained in:
@@ -3,52 +3,37 @@ package nws
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"gitea.maximumdirect.net/ejr/feedkit/config"
|
||||
"gitea.maximumdirect.net/ejr/feedkit/event"
|
||||
"gitea.maximumdirect.net/ejr/weatherfeeder/internal/sources/common"
|
||||
)
|
||||
|
||||
// AlertsSource polls an NWS alerts endpoint and will emit RAW alert Events.
|
||||
// For now Poll remains TODO; this file just migrates to the shared HTTPSource spine.
|
||||
type AlertsSource struct {
|
||||
name string
|
||||
url string
|
||||
userAgent string
|
||||
http *common.HTTPSource
|
||||
}
|
||||
|
||||
func NewAlertsSource(cfg config.SourceConfig) (*AlertsSource, error) {
|
||||
if strings.TrimSpace(cfg.Name) == "" {
|
||||
return nil, fmt.Errorf("nws_alerts: name is required")
|
||||
}
|
||||
if cfg.Params == nil {
|
||||
return nil, fmt.Errorf("nws_alerts %q: params are required (need params.url and params.user_agent)", cfg.Name)
|
||||
const driver = "nws_alerts"
|
||||
|
||||
// NWS APIs are typically GeoJSON; allow fallback to plain JSON as well.
|
||||
hs, err := common.NewHTTPSource(driver, cfg, "application/geo+json, application/json")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Driver-specific options live in cfg.Params to keep feedkit domain-agnostic.
|
||||
// Use the typed accessor so callers can’t accidentally pass non-strings to TrimSpace.
|
||||
url, ok := cfg.ParamString("url", "URL")
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("nws_alerts %q: params.url is required", cfg.Name)
|
||||
}
|
||||
|
||||
ua, ok := cfg.ParamString("user_agent", "userAgent")
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("nws_alerts %q: params.user_agent is required", cfg.Name)
|
||||
}
|
||||
|
||||
return &AlertsSource{
|
||||
name: cfg.Name,
|
||||
url: url,
|
||||
userAgent: ua,
|
||||
}, nil
|
||||
return &AlertsSource{http: hs}, nil
|
||||
}
|
||||
|
||||
func (s *AlertsSource) Name() string { return s.name }
|
||||
func (s *AlertsSource) Name() string { return s.http.Name }
|
||||
|
||||
// Kind is used for routing/policy.
|
||||
// The envelope type is event.Event; payload will eventually be something like model.WeatherAlert.
|
||||
// The envelope type is event.Event; payload will eventually normalize into model.WeatherAlert.
|
||||
func (s *AlertsSource) Kind() event.Kind { return event.Kind("alert") }
|
||||
|
||||
func (s *AlertsSource) Poll(ctx context.Context) ([]event.Event, error) {
|
||||
_ = ctx
|
||||
return nil, fmt.Errorf("nws.AlertsSource.Poll: TODO implement (url=%s)", s.url)
|
||||
return nil, fmt.Errorf("nws.AlertsSource.Poll: TODO implement")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user