feedkit now contains a reusable core, while weatherfeeder is a concrete implementation that includes weather-specific functions.
55 lines
1.5 KiB
Go
55 lines
1.5 KiB
Go
package nws
|
||
|
||
import (
|
||
"context"
|
||
"fmt"
|
||
"strings"
|
||
|
||
"gitea.maximumdirect.net/ejr/feedkit/config"
|
||
"gitea.maximumdirect.net/ejr/feedkit/event"
|
||
)
|
||
|
||
type AlertsSource struct {
|
||
name string
|
||
url string
|
||
userAgent string
|
||
}
|
||
|
||
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)
|
||
}
|
||
|
||
// 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
|
||
}
|
||
|
||
func (s *AlertsSource) Name() string { return s.name }
|
||
|
||
// Kind is used for routing/policy.
|
||
// The envelope type is event.Event; payload will eventually be something like 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)
|
||
}
|