题目:
Implement a
Reader
type that emits an infinite stream of the ASCII character'A'
.
实现一个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{})
}