Skip to content

Instantly share code, notes, and snippets.

@krry
Created March 4, 2019 01:09
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 krry/1f868594c32360caa45d8eec8d270e50 to your computer and use it in GitHub Desktop.
Save krry/1f868594c32360caa45d8eec8d270e50 to your computer and use it in GitHub Desktop.
An answer to 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) {
for i := range b {
b[i] = 'A'
}
return len(b), nil
}
func main() {
reader.Validate(MyReader{})
}
// returns:
// AAAAAAAAAAAAAAAAAA...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment