1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
package destination import "io" type hardLimitReader struct { r io.Reader n int64 } func (h *hardLimitReader) Read(p []byte) (int, error) { nRead, err := h.r.Read(p) h.n -= int64(nRead) if h.n < 0 { err = ErrEntityTooLarge } return nRead, err }