題目:
Implement a
Reader
type that emits an infinite stream of the ASCII character'A'
.
實(shí)現(xiàn)一個(gè)Reader
類型席函,只含有'A'
的流。
代碼:
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) {
for i := range b {
b[i] = 'A'
}
return len(b), nil
}
func main() {
reader.Validate(MyReader{})
}