Skip to content

Instantly share code, notes, and snippets.

@guoxingx
Created May 18, 2018 10:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save guoxingx/facd8c5ea6c4a12e869dfb0e6476ee2e to your computer and use it in GitHub Desktop.
Save guoxingx/facd8c5ea6c4a12e869dfb0e6476ee2e to your computer and use it in GitHub Desktop.
A Tour of Go - Exercise: Readers
package main
import (
"golang.org/x/tour/reader"
)
type MyReader struct{}
// TODO: Add a Read([]byte) (int, error) method to MyReader.
func (reader MyReader) Read(b []byte) (int, error) {
size := len(b)
for i := range b { b[i] = 'A' } // 'A': rune for "A"
return size, nil
}
func main() {
reader.Validate(MyReader{})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment