Add weather API bundle adapter
This commit is contained in:
@@ -72,15 +72,15 @@ func TestInvalidConfigProducesActionableError(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestLoadAppliesOverrides(t *testing.T) {
|
||||
cfg, err := Load(LoadOptions{Units: "metric", Timezone: "UTC", Output: "./out"})
|
||||
cfg, err := Load(LoadOptions{Units: "metric", Timezone: "+09:30", Output: "./out"})
|
||||
if err != nil {
|
||||
t.Fatalf("Load() error = %v", err)
|
||||
}
|
||||
if cfg.WeatherAPI.Units != "metric" {
|
||||
t.Fatalf("Units = %q, want metric", cfg.WeatherAPI.Units)
|
||||
}
|
||||
if cfg.WeatherAPI.Timezone != "UTC" {
|
||||
t.Fatalf("Timezone = %q, want UTC", cfg.WeatherAPI.Timezone)
|
||||
if cfg.WeatherAPI.Timezone != "+09:30" {
|
||||
t.Fatalf("Timezone = %q, want +09:30", cfg.WeatherAPI.Timezone)
|
||||
}
|
||||
if cfg.Reports.OutputDir != "./out" {
|
||||
t.Fatalf("OutputDir = %q, want ./out", cfg.Reports.OutputDir)
|
||||
|
||||
@@ -5,7 +5,8 @@ import (
|
||||
"net/url"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"gitea.maximumdirect.net/eric/weatherreporter/internal/timeutil"
|
||||
)
|
||||
|
||||
func Validate(cfg Config) error {
|
||||
@@ -27,7 +28,7 @@ func Validate(cfg Config) error {
|
||||
if cfg.WeatherAPI.Timezone == "" {
|
||||
return fmt.Errorf("weather_api.timezone is required")
|
||||
}
|
||||
if _, err := loadLocation(cfg.WeatherAPI.Timezone); err != nil {
|
||||
if _, err := timeutil.LoadLocation(cfg.WeatherAPI.Timezone); err != nil {
|
||||
return fmt.Errorf("weather_api.timezone %q is invalid: %w", cfg.WeatherAPI.Timezone, err)
|
||||
}
|
||||
if cfg.WeatherAPI.Format == "" {
|
||||
@@ -78,17 +79,6 @@ func Validate(cfg Config) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func loadLocation(name string) (*time.Location, error) {
|
||||
location, err := time.LoadLocation(name)
|
||||
if err == nil {
|
||||
return location, nil
|
||||
}
|
||||
if strings.Contains(name, "/") {
|
||||
return nil, err
|
||||
}
|
||||
return time.LoadLocation("America/" + name)
|
||||
}
|
||||
|
||||
func validatePolicy(name string, policy MissingSourcePolicy) error {
|
||||
switch policy {
|
||||
case MissingSourceError, MissingSourceWarn, MissingSourceNone:
|
||||
|
||||
Reference in New Issue
Block a user