The Reader Interface
The heart of Go I/O.
The Heart of Go I/O
io.Reader is one interface that unifies all input in Go: files, network connections, strings, compressed streams, and more.
Code that accepts an io.Reader works with any source.
The Interface Definition
The contract is tiny:
Read(p []byte) (n int, err error)
It fills p with up to len(p) bytes, returns how many (n) and an error.
All lessons in this course
- The Reader Interface
- The Writer Interface
- io Utility Functions
- Implementing Custom Readers