Skip to content

Instantly share code, notes, and snippets.

@jimmyfrasche
Last active September 12, 2018 17:29
Show Gist options
  • Save jimmyfrasche/04ca2146c9130dab4d993365313722fb to your computer and use it in GitHub Desktop.
Save jimmyfrasche/04ca2146c9130dab4d993365313722fb to your computer and use it in GitHub Desktop.
Error Inspection feedback

These operations would help but they're not unique to errors, even though they most often arise in that context.

Since this proposal relies on some form of generics to implement As, why not make the interface and both operations generic so we can Is or As a wrapped io.Reader just as easily?

@neild
Copy link

neild commented Sep 11, 2018

I think one of us is misunderstanding the other; my point is that As(wrappedReader, io.ReaderAt) doesn't seem to be useful under any circumstance I can see, so this doesn't appear to be an argument in favor of making the operation generic.

When do you see an unwrapping As function as being useful for non-errors?

@jimmyfrasche
Copy link
Author

When wrapping a possibly already wrapped reader you could see if it was already buffered and choose to use the minimum buffering needed to implement your wrapper's functionality, knowing that the underlying buffering will take care of the rest. It would also be useful for debugging since you could print out the entirety of the nesting (that wouldn't use As or Is, just the interface, though).

I'm sure there are use-cases for http.ResponseWriter as well since it can have lots of extra methods which makes it very hard to wrap as it is now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment