Last active
January 23, 2021 10:16
-
-
Save perbu/1c036edda2839502b26cf2c55f67ebbf to your computer and use it in GitHub Desktop.
go-error-handling
This file contains hidden or 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
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