O'Reilly logo

Go: Design Patterns for Real-World Projects by Mat Ryer, Mario Castro Contreras, Vladimir Vivien

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

The io.Writer interface

The io.Writer interface, as shown in the following code, is just as simple as its reader counterpart:

type Writer interface { 
   Write(p []byte) (n int, err error) 
} 

The interface requires the implementation of a single method, Write(p []byte)(c int, e error), that copies data from the provided stream p and writes that data to a sink resource such as an in-memory structure, standard output, a file, a network connection, or any number of io.Writer implementations that come with the Go standard library. The Write method returns the number of bytes copied from p followed by an error value if any was encountered.

The following code snippet shows the implementation of the channelWriter type, a writer that decomposes and serializes ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required