Skip to content

Instantly share code, notes, and snippets.

@hadv
Created September 10, 2017 11:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hadv/cf89c337ea74c74117fd92cd1b1af4cf to your computer and use it in GitHub Desktop.
Save hadv/cf89c337ea74c74117fd92cd1b1af4cf to your computer and use it in GitHub Desktop.
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