Skip to content

Instantly share code, notes, and snippets.

@perbu
Last active January 23, 2021 10:16
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 perbu/1c036edda2839502b26cf2c55f67ebbf to your computer and use it in GitHub Desktop.
Save perbu/1c036edda2839502b26cf2c55f67ebbf to your computer and use it in GitHub Desktop.
go-error-handling
body, err := ioutil.ReadAll(res.Body)
if err != nil {
return forecast, err // return an error and let the caller handle it
}
err = json.Unmarshal(body, &forecast)
if err != nil {
log.Fatalf("error unmarshaling body %s: %s", url, err.Error())
}
forecast.Expires, err = http.ParseTime(res.Header.Get("Expires"))
if err != nil {
panic("could not parse expires header")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment