Skip to content

Instantly share code, notes, and snippets.

@zh-f
Created June 10, 2020 03:29
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 zh-f/7a0f19d639758b50afb6b7c20b738790 to your computer and use it in GitHub Desktop.
Save zh-f/7a0f19d639758b50afb6b7c20b738790 to your computer and use it in GitHub Desktop.
Solution of Exercise: Readers
package main
import "golang.org/x/tour/reader"
type MyReader struct{}
// TODO: Add a Read([]byte) (int, error) method to MyReader.
func (r *MyReader) Read (b []byte) (n int, err error){
b = b[:cap(b)]
for i := range b {
b[i] = 'A'
}
return len(b), nil
}
func main() {
reader.Validate(&MyReader{})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment