On Wed, Dec 30, 2020 at 4:07 AM Amnon <amno...@gmail.com> wrote: > > How do you know, if you don't check? FTR, it's not just about sending > garbage, it's also about requests accidentally being truncated or just > generally garbled. > > json.NewDecoder(r.Body).Decode(&payload) will return an error if the request > is garbled or truncated. > > The other nice thing about this code is that it composes nicely with the > context. > net/http provides the body as a Reader. And json NewDecoder takes a reader. > The two fit together nicely, without any need > for adapters.
This is a good point, I like that viewpoint. -- 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. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CANODV3%3D0DOQsBs_EWyTk05ZJk1g0TDj2XwM3GKPBdJtQWvhrTQ%40mail.gmail.com.