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}
Written by Marko Mikulicic
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Golang
Authors
Related Tags
#golang
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#