A package that provides a way to limit the amount of bytes read from an
io.ReadCloser.
The io package only provides a io.LimitedReader, it doesn't provide a LimitedReadCloser, which can be very useful for working with http, files,
etc, etc.
Say you want to create a middleware that limits any handler from reading
over 10 bytes. You remember the awesome io.LimitReader function, but then
realize Body is a ReadCloser, not just a Reader! With limit we can
easily implement this middleware, because it has LimitedReadCloser, which
has an underlying io.ReadCloser. For a more complete example see here.
func limitMiddleware(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
r.Body = limit.ReadCloser(r.Body, 10)
next.ServeHTTP(w, r)
})
}