November 2017
Intermediate to advanced
670 pages
17h 35m
English
As if that's not enough reason to design using interfaces.
We also get access to a plethora of functionality. For example, when working with readers and writers, we get the following for free:
| Free functionality | Description |
|
io.Copy |
// Copy copies from src to dst until either EOF is reached// on src or an error occurs. It returns the number of bytes// copied and the first error encountered while copying, if any.func Copy(dst Writer, src Reader) (written int64, err error) { return copyBuffer(dst, src, nil)} |
|
io.LimitReader |
// A LimitedReader reads from R but limits the amount of// data returned to just N bytes. Each call to Read// updates N to reflect the new amount remaining.// Read returns ... |