3 ms·
I am just wondering whether you can write your own wrapper class that implements (exposes) the read method and doesn't expose a close method (or expose a close
by rjempson 13y ago
I am just wondering whether you can write your own wrapper class that implements (exposes) the read method and doesn't expose a close method (or expose a close method that does nothing) and pass that in?
I am not suggesting this is a good solution, just curious.
- enneff 13y agoYes, easily: var rc io.ReadCloser // a file, whatever readerOnly := struct{io.Reader}{rc} // only a Reader
- frou_dh 13y agoThat's cool. The io.Reader is an unnamed field, so its method is effectively pushed to the surface of the wrapping struct instead of needing to be explicitly forwarded to.