cache async while the user uses the interface

This commit is contained in:
Jan Barfuss 2024-11-14 10:16:56 +01:00
parent baf110f9f3
commit 47c43856f1

View File

@ -34,6 +34,10 @@ func Run(env map[string]string) {
// Parse query parameters
tempCelsius, relativeHumidity := r.URL.Query().Get("temp"), r.URL.Query().Get("rh")
if tempCelsius == "" || relativeHumidity == "" {
go func(cacheW **models.WeatherCache) {
humidity, temperature := internal.Weather(env)
(*cacheW).SetData(humidity, temperature)
}(&cacheWeather)
tmpl.Execute(w, nil)
return
}