Proxy support for AWN/Wunderground

This commit is contained in:
2025-01-12 15:30:37 -05:00
parent 849dbfb6ff
commit 7fc1fc9b56
9 changed files with 228 additions and 39 deletions

View File

@ -1,6 +1,10 @@
package weather
import "math"
import (
"math"
"net/url"
"strconv"
)
// Attempts to complete missing fields that may not
// be set by a specific provider, such as DewPoint and WindChill
@ -53,3 +57,31 @@ func CalculateWindChill(tempF float64, windSpeedMPH float64) float64 {
35.75*math.Pow(windSpeedMPH, 0.16) +
0.4275*tempF*math.Pow(windSpeedMPH, 0.16)
}
// Helper function to set values from fields
// typically from a WeatherUpdate
func SetURLVal(vals *url.Values, key string, value any) {
if value == nil {
return
}
switch v := value.(type) {
case *float64:
if v == nil {
return
}
str := strconv.FormatFloat(*v, 'f', 4, 64)
vals.Set(key, str)
case *int:
if v == nil {
return
}
str := strconv.FormatInt(int64(*v), 10)
vals.Set(key, str)
case *string:
if v == nil {
return
}
vals.Set(key, *v)
}
}