Exercise: ReadersRozwiązanie dla http://tour.golang.org/methods/11
Wdrożenie typ czytnika, który emituje nieskończony strumień znak ASCII „A”.
Nie rozumiem pytania, jak emitować znak "A"? do jakiej zmiennej mam ustawić tę postać?
Oto, co starałem:
package main
import "code.google.com/p/go-tour/reader"
type MyReader struct{}
// TODO: Add a Read([]byte) (int, error) method to MyReader.
func (m MyReader) Read(b []byte) (i int, e error) {
b = append(b,'A') // this is wrong..
return 1, nil // this is also wrong..
}
func main() {
reader.Validate(MyReader{}) // what did this function expect?
}
Czytaj powinien odczytać dane do dostarczonego bufora, nie dołączać do niego. – Arjan
odpowiedzi: https://gist.github.com/inancgumus/d25d045b4cec43dcbb111e04980d396b –