How to do it...

These steps cover writing and running your application:

  1. From your terminal/console application, create a new directory called chapter1/bytestrings.
  2. Navigate to this directory.

  1. Copy tests from https://github.com/agtorre/go-cookbook/tree/master/chapter1/bytesstrings, or use this as an exercise to write some of your own code!
  2. Create a file called buffer.go with the following contents:
        package bytestrings                import (                "bytes"                "io"                "io/ioutil"        )                // Buffer demonstrates some tricks for initializing bytes            //Buffers        // These buffers implement an io.Reader interface        func Buffer(rawString string) *bytes.Buffer {                        // we'll start with a string encoded into raw bytes                rawBytes := []byte(rawString)         // there are a number of ways to ...

Get Go Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.