Created
September 10, 2017 11:06
-
-
Save hadv/cf89c337ea74c74117fd92cd1b1af4cf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type apixu struct { | |
apiKey string | |
} | |
func (w apixu) temperature(city string) (float64, error) { | |
resp, err := http.Get("http://api.apixu.com/v1/current.json?key=" + w.apiKey + "&q=" + city) | |
if err != nil { | |
return 0, err | |
} | |
defer resp.Body.Close() | |
var d struct { | |
Observation struct { | |
Celsius float64 `json:"temp_c"` | |
} `json:"current"` | |
} | |
if err := json.NewDecoder(resp.Body).Decode(&d); err != nil { | |
return 0, err | |
} | |
kelvin := d.Observation.Celsius + 273.15 | |
log.Printf("apixu: %s: %.2f", city, kelvin) | |
return kelvin, nil | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment