Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

io/ioutil: nopCloser makes it impossible to assert to the enclosed type #12235

Closed
skelterjohn opened this issue Aug 20, 2015 · 4 comments
Closed

Comments

@skelterjohn
Copy link
Contributor

Because ioutil.noopCloser is not exported, one cannot assert a io.ReadCloser to its original type.

@skelterjohn
Copy link
Contributor Author

If the io.ReadCloser contains a noopCloser, that is.

@bradfitz
Copy link
Contributor

This is true. What's the larger problem? We're unlikely to export this.

@skelterjohn
Copy link
Contributor Author

I came across this while writing some tests for code that made http
requests, and I wanted to inspect the request bodies, which were
bytes.Buffer instances (underneed the nopCloser). In this case, I can read
the data out and inspect that.

But, it seems odd to have a type that adds a noop method and obscures the
underlying type, for seemingly no reason beyond a default stance of not
exporting things (which is a good default stance).

On Thu, Aug 20, 2015 at 4:07 PM, Brad Fitzpatrick notifications@github.com
wrote:

This is true. What's the larger problem? We're unlikely to export this.


Reply to this email directly or view it on GitHub
#12235 (comment).

@bradfitz
Copy link
Contributor

I often hide stuff in anonymous structs or unexported things on purpose so I can use some implementation (like a *bytes.Buffer) myself but not leak that detail across package boundaries, so I don't have to be locked in to that implementation, and have people messing with internals (e.g. *bytes.Buffer.Bytes() []byte and mutating it)

I think this is working as intended, or at least nothing to do.

@mikioh mikioh changed the title ioutil.noopCloser makes it impossible to assert to the enclosed type io/ioutil: nopCloser makes it impossible to assert to the enclosed type Aug 21, 2015
@golang golang locked and limited conversation to collaborators Aug 22, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants