d MaxBytesReader) which makes writing the middleware quite simple. Note that the way I write middleware is heavily inspired by Mat Ryer’s adapter pattern. Here’s the code:
// Represents a piece of HTTP middleware. type Middleware func(http.Handler) http.Handler // Limit the size of the request body to 4KB. const MaxRequestBodySize = 4 * 1024 // Places an upper limit on the size of every request body. func LimitRequestBodySize() Middleware { return func(next http.Handler) http.Handler { return http.Handl