Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
18 lines (15 sloc) 356 Bytes
// Define a new type, myReader, as a struct with a field and a method.
methodik myReader struct { Source string } {
func (r) Read(b []byte) (int, error) {
n := copy(b, r.Source)
r.Source = r.Source[n:]
if n == 0 {
import "io"
return 0, io.EOF
}
return n, nil
}
}
r := &myReader{"OK"}
import "io/ioutil"
print(string(ioutil.ReadAll(r)))