octolab / pkg

🧰 Go packages.

Home Page:https://go.octolab.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

improve io.Discard for defer

kamilsk opened this issue · comments

if I use io.Discard with defer I have bad dev experience:

resp, err := http.Do(req)
if err {...}
defer safe.Close(io.Discard(resp.Body), ...) // now I can't read from body

json.NewDecoder(resp.Body).Decode() // woops

and write docs with tests