add web ui
This commit is contained in:
@@ -17,34 +17,48 @@ type OpenMeteo struct {
|
||||
|
||||
func (o *OpenMeteo) Name() string { return "open_meteo" }
|
||||
|
||||
var openMeteoHourlyFields = []string{
|
||||
"temperature_2m",
|
||||
"pressure_msl",
|
||||
"wind_speed_10m",
|
||||
"wind_gusts_10m",
|
||||
"wind_direction_10m",
|
||||
"precipitation",
|
||||
"cloud_cover",
|
||||
"relative_humidity_1000hPa",
|
||||
}
|
||||
|
||||
func OpenMeteoRequestURL(site Site, model string) (string, error) {
|
||||
u, err := url.Parse("https://api.open-meteo.com/v1/ecmwf")
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
q := u.Query()
|
||||
q.Set("latitude", fmt.Sprintf("%.6f", site.Latitude))
|
||||
q.Set("longitude", fmt.Sprintf("%.6f", site.Longitude))
|
||||
q.Set("hourly", join(openMeteoHourlyFields))
|
||||
q.Set("wind_speed_unit", "ms")
|
||||
q.Set("temperature_unit", "celsius")
|
||||
q.Set("precipitation_unit", "mm")
|
||||
u.RawQuery = q.Encode()
|
||||
_ = model // endpoint is fixed to ECMWF; model is metadata only.
|
||||
return u.String(), nil
|
||||
}
|
||||
|
||||
func (o *OpenMeteo) Fetch(ctxDone <-chan struct{}, site Site, model string) (*ForecastResult, error) {
|
||||
if o.Client == nil {
|
||||
o.Client = &http.Client{Timeout: 15 * time.Second}
|
||||
}
|
||||
|
||||
// Hourly fields supported by the ECMWF endpoint.
|
||||
hourly := []string{
|
||||
"temperature_2m",
|
||||
"pressure_msl",
|
||||
"wind_speed_10m",
|
||||
"wind_gusts_10m",
|
||||
"wind_direction_10m",
|
||||
"precipitation",
|
||||
"cloud_cover",
|
||||
"relative_humidity_1000hPa",
|
||||
reqURL, err := OpenMeteoRequestURL(site, model)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
u, _ := url.Parse("https://api.open-meteo.com/v1/ecmwf")
|
||||
q := u.Query()
|
||||
q.Set("latitude", fmt.Sprintf("%.6f", site.Latitude))
|
||||
q.Set("longitude", fmt.Sprintf("%.6f", site.Longitude))
|
||||
q.Set("hourly", join(hourly))
|
||||
q.Set("wind_speed_unit", "ms")
|
||||
q.Set("temperature_unit", "celsius")
|
||||
q.Set("precipitation_unit", "mm")
|
||||
u.RawQuery = q.Encode()
|
||||
|
||||
safeURL := *u
|
||||
safeURL, err := url.Parse(reqURL)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
safeQuery := safeURL.Query()
|
||||
if safeQuery.Has("apikey") {
|
||||
safeQuery.Set("apikey", "redacted")
|
||||
@@ -56,7 +70,7 @@ func (o *OpenMeteo) Fetch(ctxDone <-chan struct{}, site Site, model string) (*Fo
|
||||
defer cancel()
|
||||
go func() { <-ctxDone; cancel() }()
|
||||
|
||||
req, _ := http.NewRequestWithContext(ctx, "GET", u.String(), nil)
|
||||
req, _ := http.NewRequestWithContext(ctx, "GET", reqURL, nil)
|
||||
resp, err := o.Client.Do(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
Reference in New Issue
Block a user