0Pricing
Go Academy · Lesson

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

  1. The Reader Interface
  2. The Writer Interface
  3. io Utility Functions
  4. Implementing Custom Readers
← Back to Go Academy