You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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).
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
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
Because ioutil.noopCloser is not exported, one cannot assert a io.ReadCloser to its original type.
The text was updated successfully, but these errors were encountered: