diff options
| author | siddharth ravikumar <s@ricketyspace.net> | 2022-08-13 12:54:23 -0400 | 
|---|---|---|
| committer | siddharth ravikumar <s@ricketyspace.net> | 2022-08-13 12:56:03 -0400 | 
| commit | dad7d63d2fa36bec8f0bfa46febdb0d6faa035e6 (patch) | |
| tree | 7b069e3775ea4138b625d1dd05f5bbad2bcef361 /weather | |
| parent | 4f735265799888dd77b1c8287db2522d3d9daa48 (diff) | |
weather: update `humidity`
- Change return type to just (int).
- Add check to skip a value if it's < 1.
Diffstat (limited to 'weather')
| -rw-r--r-- | weather/weather.go | 19 | 
1 files changed, 9 insertions, 10 deletions
diff --git a/weather/weather.go b/weather/weather.go index e72b601..0e981a1 100644 --- a/weather/weather.go +++ b/weather/weather.go @@ -60,11 +60,7 @@ func NewWeather(lat, lng float32) (*Weather, error, int) {  	}  	// Get humidity from the grid data. -	h, err := humidity(fBundle.ForecastGrid) -	if err != nil { -		return nil, err, 500 -	} - +	h := humidity(fBundle.ForecastGrid)  	w := new(Weather)  	w.Location = fmt.Sprintf("%s, %s",  		strings.ToLower(fBundle.Point.Properties.RelativeLocation.Properties.City), @@ -148,18 +144,21 @@ func NewWeather(lat, lng float32) (*Weather, error, int) {  	return w, nil, 200  } -func humidity(g *nws.ForecastGrid) (int, error) { +func humidity(g *nws.ForecastGrid) int {  	if g == nil { -		return 0, fmt.Errorf("humdity: forecast grid data empty") +		return 0  	}  	for _, v := range g.Properties.RelativeHumidity.Values { +		if v.Value < 1 { +			continue +		}  		yes, err := t.IsCurrent(v.ValidTime)  		if err != nil { -			return 0, fmt.Errorf("humidity: %v", err) +			return 0  		}  		if yes { -			return v.Value, nil +			return v.Value  		}  	} -	return 0, fmt.Errorf("humidity: not found") +	return 0  }  | 
