io.Writer
The Go interface for anything you can write bytes to, such as a file, standard output, a buffer or an HTTP response.
In more detail
Its one method, Write, takes a byte slice. fmt.Fprintf, io.Copy and json.NewEncoder all write to any io.Writer, so the same code can print to a terminal or fill a buffer in a test.
Example
var target bytes.BufferRelated terms
- io.Reader — The Go interface for anything you can read bytes from, such as a file, a network connection or an HTTP response body.
- fmt.Fprintf — The fmt functions that write formatted text to a destination you choose, such as os.Stderr, a file or an HTTP response.
- io.Copy — The Go function that streams all the bytes from an io.Reader to an io.Writer and returns how many it copied.
- http.ResponseWriter — The Go interface a handler uses to send its response: set headers, write the status code with WriteHeader, then write the body.
Taught in
- Streams and the io Package — Concurrent Systems Programming with Go