dcrtime
dcrtime copied to clipboard
Close the request body with a middleware instead of within the handler function body
As mentioned by Luke here: https://github.com/decred/dcrtime/pull/84#discussion_r1021757335.
We already have the middleware defined here: https://github.com/decred/dcrtime/blob/bbebe6df45a8c650c4e605d778494480b056f121/dcrtimed/dcrtimed.go#L1297
And are using it here: https://github.com/decred/dcrtime/blob/bbebe6df45a8c650c4e605d778494480b056f121/dcrtimed/dcrtimed.go#L1306
As we add every route with the addRoute
method. It should be already working so the calls to defer r.Body.Close
inside handler functions are redundant and can be removed.