Decorate types to implement io.Reader interface
The io package has provided a bunch of handy read functions and methods, but unfortunately, they all require the arguments satisfy io.Reader interface. See the following example:
package main import ( "fmt" "io" ) func main() { s := "Hello, world!" p := make([]byte, len(s)) if _, err := io.ReadFull(s, p); err != nil { fmt.Println(err) } else { fmt.Printf("%s\n", p) } } Compile above program and an error is generated:
[Read More]