Last active
July 22, 2025 13:16
-
-
Save rndD/5ba3c7c9883de396a4ea to your computer and use it in GitHub Desktop.
A tour of Go: Exercise: Readers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import "code.google.com/p/go-tour/reader" | |
| type MyReader struct{} | |
| func (r MyReader) Read(bytes []byte) (int, error) { | |
| for i := range bytes { | |
| bytes[i] = 65 | |
| } | |
| return len(bytes), nil | |
| } | |
| // TODO: Add a Read([]byte) (int, error) method to MyReader. | |
| func main() { | |
| reader.Validate(MyReader{}) | |
| } |
Author
The description of the problem didn't make sense to me. Thank you for the solution.
You are welcome
This is much nicer than what I had. I just stubbed in the following and was surprised when it actually passed lol!
func (r MyReader) Read(b []byte) (int, error) {
b[0] = 'A'
return 1, nil
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The description of the problem didn't make sense to me. Thank you for the solution.