Created
February 29, 2020 16:08
-
-
Save Pygmalion69/7109648716dda9e4d82d6e656c73ba41 to your computer and use it in GitHub Desktop.
A Tour of Go - Exercise: Reader
This file contains 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
// https://tour.golang.org/methods/22 | |
package main | |
import "golang.org/x/tour/reader" | |
type MyReader struct{} | |
func (r MyReader) Read(b []byte) (int, error) { | |
for i := range b { | |
b[i] = 65 | |
} | |
return len(b), nil | |
} | |
/* Shortest solution that validates | |
func (r MyReader) Read(b []byte) (int, error) { | |
b[0] = 65 | |
return 1, nil | |
} | |
*/ | |
func main() { | |
reader.Validate(MyReader{}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment