weatherfeeder: split the former maximumdirect.net/weatherd project in two.
feedkit now contains a reusable core, while weatherfeeder is a concrete implementation that includes weather-specific functions.
This commit is contained in:
56
internal/sources/builtins.go
Normal file
56
internal/sources/builtins.go
Normal file
@@ -0,0 +1,56 @@
|
||||
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"
|
||||
|
||||
"gitea.maximumdirect.net/ejr/feedkit/config"
|
||||
fksource "gitea.maximumdirect.net/ejr/feedkit/sources"
|
||||
)
|
||||
|
||||
// RegisterBuiltins registers the source drivers that ship with this binary.
|
||||
// Keeping this in one place makes main.go very readable.
|
||||
func RegisterBuiltins(r *fksource.Registry) {
|
||||
// NWS drivers
|
||||
r.Register("nws_observation", func(cfg config.SourceConfig) (fksource.Source, error) {
|
||||
return nws.NewObservationSource(cfg)
|
||||
})
|
||||
r.Register("nws_alerts", func(cfg config.SourceConfig) (fksource.Source, error) {
|
||||
return nws.NewAlertsSource(cfg)
|
||||
})
|
||||
r.Register("nws_forecast", func(cfg config.SourceConfig) (fksource.Source, error) {
|
||||
return nws.NewForecastSource(cfg)
|
||||
})
|
||||
|
||||
// Open-Meteo drivers
|
||||
r.Register("openmeteo_observation", func(cfg config.SourceConfig) (fksource.Source, error) {
|
||||
return openmeteo.NewObservationSource(cfg)
|
||||
})
|
||||
|
||||
// OpenWeatherMap drivers
|
||||
r.Register("openweather_observation", func(cfg config.SourceConfig) (fksource.Source, error) {
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user