So, I’m working on parsing a POST using GO. What I want is the body of the post, so I try the following (r is of type *http.Request in this context):
var body io.Reader
var d []byte
body = r.Body.Reader
body.Read( d)
However, this results in a compilation error:
Compile error: <file>:44:
r.Body.Reader undefined (type io.ReadCloser has no field or method Reader)
Odd. I could have sworn that it was defined in the docs… Ah! here it is.
Now, I’m fairly new to Go, but this smells a little odd — what have I screwed up?
From your link, the doc for a
ReadCloseris:What this is telling you, is that a ReadCloser interface is composed of a
Readerand aCloserfunctionality. It IS both. That means theReadClosertakes on those interface definitions. They are not actually members, the way you are accessing them.A
Readeris:So that means you should be accessing
Readlike this: