June 2017
Intermediate to advanced
400 pages
10h 32m
English
Go provides a number of I/O interfaces used throughout the standard library. It is a best practice to make use of these interfaces wherever possible rather than passing structs or other types directly. Two powerful interfaces we explore in this recipe are the io.Reader and io.Writer interfaces. These interfaces are used throughout the standard library and understanding how to use them will make you a better Go developer.
The Reader and Writer interfaces look like this:
type Reader interface { Read(p []byte) (n int, err error)}type Writer interface { Write(p []byte) (n int, err error)}
Go also makes it easy to combine interfaces. For example, take a look at the following code:
type Seeker interface { Seek(offset ...Read now
Unlock full access