Updates in preparation for adding forecast sources.

This commit is contained in:
2026-01-16 00:04:37 -06:00
parent e10ba804ca
commit 0fcc536885
6 changed files with 162 additions and 61 deletions

View File

@@ -1,8 +1,6 @@
package sources
import (
"fmt"
"gitea.maximumdirect.net/ejr/weatherfeeder/internal/sources/nws"
"gitea.maximumdirect.net/ejr/weatherfeeder/internal/sources/openmeteo"
"gitea.maximumdirect.net/ejr/weatherfeeder/internal/sources/openweather"
@@ -35,22 +33,3 @@ func RegisterBuiltins(r *fksource.Registry) {
return openweather.NewObservationSource(cfg)
})
}
// Optional: centralize some common config checks used by multiple drivers.
//
// NOTE: feedkit/config.SourceConfig intentionally keeps driver-specific options
// inside cfg.Params, so drivers can evolve independently without feedkit
// importing domain config packages.
func RequireURL(cfg config.SourceConfig) error {
if cfg.Params == nil {
return fmt.Errorf("source %q: params.url is required", cfg.Name)
}
// Canonical key is "url". We also accept "URL" as a convenience.
url, ok := cfg.ParamString("url", "URL")
if !ok {
return fmt.Errorf("source %q: params.url is required", cfg.Name)
}
_ = url // (optional) return it if you want this helper to provide the value
return nil
}

View File

@@ -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 cant 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")
}