Skip to content

Instantly share code, notes, and snippets.

@kyleconroy
Created November 7, 2014 17:05
Show Gist options
  • Save kyleconroy/44ecda49fccdc859aa1f to your computer and use it in GitHub Desktop.
Save kyleconroy/44ecda49fccdc859aa1f to your computer and use it in GitHub Desktop.
// write this
import (
"encoding/json"
"net/http"
)
func foo() (int, err) {
resp := try(resp.Get("http://api.stripe.com"))
body := try(ioutil.ReadAll(resp.Body))
return len(body), nil
}
// to this
import (
"encoding/json"
"net/http"
)
func foo() (int, err) {
resp, err := resp.Get("http://api.stripe.com")
if err != nil {
return 0, err
}
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return 0, err
}
return len(body), nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment