Back to Gotraining

README

topics/go/packages/io/README.md

latest2.2 KB
Original Source

io - Standard Library

The ability to stream and pass data around is incredibility important. Data is constantly coming at our programs whether over a socket, file, device, etc. Many times this data needs to just be moved from one stream. Sometimes it needs to be encrypted, hashed or stored for safe keeping. The Writer and Reader interfaces may be the most heavily used and supported interfaces in both the standard library and the community.

Notes

  • The standard library provides all the infrastructure we need to stream and work with data.
  • If we implement the Reader and Writer interfaces in our own types, we get this functionality for free.
  • Implementing interfaces to existing functionality saves us from both development time and bugs.

Documentation

Interface Declarations

io package
Go Walkthrough: io package - Ben Johnson

Code Review

Standard Library Working Together (Go Playground)
Simple curl with io.Reader and io.Writer (Go Playground)
MultiWriters with curl example (Go Playground)
Stream processing (Go Playground)

Advanced Code Review

TeeReader and io composition (Go Playground)
Gzip and Md5 support with curl example (Go Playground)

Exercises

Exercise 1

Download any document from the web and display the content in the terminal and write it to a file at the same time.

Template (Go Playground) | Answer (Go Playground)


All material is licensed under the Apache License Version 2.0, January 2004.