Writers and decorators
There are a plethora of tools to enhance, decorate, and use for readers, but the same thing does not apply to writers.
There is also the io.WriteString function, which prevents unnecessary conversions from strings to bytes. First, it checks whether the writer supports string writing, attempting a cast to io.stringWriter, an unexported interface with just the WriteString method, then writes the string if successful, or converts it into bytes otherwise.
There is the io.MultiWriter function, which creates a writer that replicates the information to a series of other writers, which it receives upon creation. A practical example is writing some content while showing it on the standard output, as in the following example: ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access