briandowns/openweathermap

[ISSUE] Error Marshaling Json Response

AllenKaplan opened this issue · 1 comments

On the following code snippet, I get the error
json: cannot unmarshal string into Go struct field CurrentWeatherData.cod of type int on some locations (e.g. Canais) but others (e.g. Toronto, China) work.
Code:

w, err := owm.NewCurrent("C", "EN", OPEN_WEATHER_API_KEY)
if err != nil {
	return nil, err
}

if err := w.CurrentByName(location); err != nil {
		return nil, err
}

I have tested the api response and it appears to be correct. The most confusing thing is that the "cod" field in the Json response does have an int.

Fixed; Issue was that location had a leading space. Perhaps CurrentByName can trim the input? Improving the 404 output would have helped me as well.