~/Golang Reader and Writer Interfaces Explained with Examples
Mar 22, 2019
The io.Reader and io.Writer interfaces are essential for input and output in Go.
A Reader is any type that implements the method
|
|
A Writer is any type that implements the method
|
|
To write your own, define a type with either method signature.
Example - A Simple Reader:
Example - A Simple Writer:
When implementing Reader, return io.EOF
when complete. For Writer, always report bytes written and any errors. Follow examples in the Go standard library.
For a deeper dive, see the Go Blog on Readers and Writers.