Re: [go-nuts] ioutil.ReadAll()
On 14 Feb 2018, at 10:50, mrx mailto:patrik@gmail.com>> wrote: resp, err := http.Get("http://example.com/";) if err != nil { // handle error } defer resp.Body.Close() body, err := ioutil.ReadAll(resp.Body) That err returned from ReadAll. I cannot see how that can possibly fail. You need a more vivid imagination. The server might crash, the network might fail, a firewall in between might reboot, and so on. Any issue along the path might result in a timeout, short read (server said “content-lenght: 42” only sent five bytes), or other errors. //jb -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [go-nuts] ioutil.ReadAll()
For example: https://play.golang.org/p/ycoR-jU48J9 The only read error it ignores is io.EOF (which makes complete sense, when you think about it), everything else get passed up. On Tue, Feb 13, 2018 at 9:19 AM, Patrik Iselind wrote: > Hi, > > I have a hard time imagining when https://golang.org/pkg/io/ > ioutil/#ReadAll would produce err != nil. The documentation doesn't tell > either. It would help when writing unittests for code that use > ioutil.ReadAll(). > > // Patrik > > -- > You received this message because you are subscribed to the Google Groups > "golang-nuts" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to golang-nuts+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[go-nuts] ioutil.ReadAll()
Hi, I have a hard time imagining when https://golang.org/pkg/io/ioutil/#ReadAll would produce err != nil. The documentation doesn't tell either. It would help when writing unittests for code that use ioutil.ReadAll(). // Patrik -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.