Last Updated: February 25, 2016
·
953
· mmikulicic

Quick ReadCloser with an anonymous struct

I have an internal API that returns io.ReadCloser and I wanted to wrap in a charset decoder. I found the excellent github.com/axgle/mahonia library, but it only provides an io.Reader.

However, I found that's it's quite easy to create a simple pass-through io.ReadCloser with anonymous structs withs anonymous fields:

rc := struct {
  io.Reader
  io.Closer
}{mahonia.NewDecoder("latin2").NewReader(r), r}