That's a ten lines-worth custom reader [1]:
type SkipWsReader struct {
r io.Reader
pass bool
}
func NewSkipWsReader(r io.Reader) *SkipWsReader {
return &SkipWsReader{r: r}
}
func (swr *SkipWsReader) Read(b []byte) (n int, err error) {
for {
n, err = swr.r.Read(b)
if swr.pass || err != nil {
return
}
for i, c := range b[0:n] {
switch c {
case '\t', '\v', '\n', '\x20':
continue
default:
n = copy(b, b[i:n])
swr.pass = true
return
}
}
}
}
The downside of this code is that if the underlying reader fails while
reading leading whitespace, that whitespase will end up in the
client-supplied slice, but that would require a bit more advanced logic
which I don't have time to mess with at the moment ;-)
1.
http://play.golang.org/p/n1-YcMkHr1