type openWeatherMap struct{}
...
var d struct {
Main struct {
Kelvin float64 `json:"temp"`
} `json:"main"`
}
if err := json.NewDecoder(resp.Body).Decode(&d); err != nil {
return 0, err
}
There is a "type" struct at the top, but then another struct without a type later on. Then there's a nested struct, and then backticks with double quotes and json with colons - one with the backticks after float64, and the other after a brace. Then rather than returning the result of the json response with an equal sign, the json decoder line takes in both the response and the output as function parameters! And one of them has an ampersand in front?!Time and time again Go is said to be a simple language, but can you really say that the Python equivalent of that example is more difficult to understand?
>>> decoded_json = json.load(urllib.request.urlopen('https://httpbin.org/get'))
>>> print(decoded_json)
Come on now.