Added a /conditions/current endpoint with computed best-guess values for current conditions
All checks were successful
ci/woodpecker/push/build-image Pipeline was successful
All checks were successful
ci/woodpecker/push/build-image Pipeline was successful
This commit is contained in:
@@ -10,6 +10,7 @@ import (
|
||||
"gitea.maximumdirect.net/ejr/weatherapi/internal/adapters/httpapi"
|
||||
adapterpg "gitea.maximumdirect.net/ejr/weatherapi/internal/adapters/postgres"
|
||||
"gitea.maximumdirect.net/ejr/weatherapi/internal/application/alerts"
|
||||
"gitea.maximumdirect.net/ejr/weatherapi/internal/application/conditions"
|
||||
"gitea.maximumdirect.net/ejr/weatherapi/internal/application/forecasts"
|
||||
"gitea.maximumdirect.net/ejr/weatherapi/internal/application/observations"
|
||||
"gitea.maximumdirect.net/ejr/weatherapi/internal/application/units"
|
||||
@@ -51,7 +52,7 @@ func main() {
|
||||
log.Fatalf("unsupported datasource type %T for driver %q", ds, dbCfg.Driver)
|
||||
}
|
||||
|
||||
converter, err := newDefaultConverter()
|
||||
unitRegistry, err := newUnitRegistry()
|
||||
if err != nil {
|
||||
log.Fatalf("configure units: %v", err)
|
||||
}
|
||||
@@ -60,18 +61,19 @@ func main() {
|
||||
fcRepo := adapterpg.NewForecastRepository(pgDataSource.Pool())
|
||||
alertRepo := adapterpg.NewAlertRepository(pgDataSource.Pool())
|
||||
|
||||
obsSvc := observations.NewService(obsRepo, converter, constants.ObservationWindow)
|
||||
fcSvc := forecasts.NewService(fcRepo, converter, constants.ForecastQueryLimit)
|
||||
obsSvc := observations.NewService(obsRepo, unitRegistry)
|
||||
conditionsSvc := conditions.NewService(obsRepo, unitRegistry, constants.ObservationWindow)
|
||||
fcSvc := forecasts.NewService(fcRepo, unitRegistry, constants.ForecastQueryLimit)
|
||||
alertsSvc := alerts.NewService(alertRepo)
|
||||
|
||||
server := httpapi.NewServer(obsSvc, fcSvc, alertsSvc)
|
||||
server := httpapi.NewServer(obsSvc, conditionsSvc, fcSvc, alertsSvc)
|
||||
|
||||
httpServer := &http.Server{
|
||||
Addr: *addr,
|
||||
Handler: server.Handler(),
|
||||
}
|
||||
|
||||
log.Printf("weatherapi listening on %s (db=%s driver=%s units=%s)", *addr, dbCfg.Name, dbCfg.Driver, constants.DefaultOutputUnitSystem)
|
||||
log.Printf("weatherapi listening on %s (db=%s driver=%s units=per-request)", *addr, dbCfg.Name, dbCfg.Driver)
|
||||
if err := httpServer.ListenAndServe(); err != nil && err != http.ErrServerClosed {
|
||||
log.Fatalf("http server: %v", err)
|
||||
}
|
||||
@@ -92,11 +94,19 @@ func chooseDatabase(cfg *config.Config, name string) (config.DatabaseConfig, err
|
||||
return db, nil
|
||||
}
|
||||
|
||||
func newDefaultConverter() (units.Converter, error) {
|
||||
switch constants.DefaultOutputUnitSystem {
|
||||
case "us":
|
||||
return units.USConverter{}, nil
|
||||
default:
|
||||
return nil, fmt.Errorf("unsupported default output unit system %q", constants.DefaultOutputUnitSystem)
|
||||
func newUnitRegistry() (*units.Registry, error) {
|
||||
registry := units.NewRegistry()
|
||||
if err := registry.Register(units.StaticFactory{
|
||||
UnitSystem: constants.UnitSystemUS,
|
||||
Converter: units.USConverter{},
|
||||
}); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := registry.Register(units.StaticFactory{
|
||||
UnitSystem: constants.UnitSystemMetric,
|
||||
Converter: units.MetricConverter{},
|
||||
}); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return registry, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user