Supply an `io.Writer` but check it against the `WriterResetter`
interface to see if we can call `Reset()`. Which is a neat solution!
Add a new test to check that a supplied `bytes.Buffer` gets reset
between API calls.
After going through several other solutions, there's no clean way
to use an `io.Writer` but also be able to call `Reset()` between
writes. Filehandles can't `Reset()` and buffers can't `Seek()`.
But then if you supplied `os.Stderr`, you'd be expecting appending
and a `Seek()` would be nonsense.
My own preference would be to make `JSONWriter` a strict `*bytes.Buffer`
which lets the library handle the resetting and the client do any
outputting if required - I can't see much value in ever supplying
a non-`bytes.Buffer` as `JSONWriter`.
As suggested by 'mattn, use a `TeeReader` with an `io.Writer` to keep
the semantics of `json.NewDecoder().Decode()` whilst also being able
to save the JSON if requested by the client.
However we need to use our own interface (`WriteResetter`) in order to
be able to call `Reset()` on the underlying buffer (which does somewhat
limit the usage to buffers instead of generic `io.Writer` and may not
be the 100% ideal solution.)
For my archival purposes, I like to keep the raw API JSON around
as it often contains things not picked up by the various objects.
e.g. getting a status from my Akkoma instance contains a whole
`pleroma` extension block that's not reflected in `mastodon.Status`.
Maybe this should be gated by an option when creating the `Client`
since it's probably only relevant to 1% of library users.
The goroutine started from test must not call t.Fatal, but t.Error. Adds
a sync.WaitGroup to make sure all goroutines have a chance to report an
error before test stops.