Hacker News new | past | comments | ask | show | jobs | submit login

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.




Yes, easily:

    var rc io.ReadCloser // a file, whatever
    readerOnly := struct{io.Reader}{rc} // only a Reader


That'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.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: