Here is the problematic source code:
http://play.golang.org/p/lcN4Osdkgs
package main
import(
"net/url"
"io"
"strings"
)
func main(){
v := url.Values{"key": {"Value"}, "id": {"123"}}
body := strings.NewReader(v.Encode())
_ = proxy(body)
// this work
//invalid type assertion: body.(io.ReadCloser) (non-interface type *strings.Reader on left)
_, _ = body.(io.ReadCloser)
}
func proxy( body io.Reader) error{
_, _ = body.(io.ReadCloser)
return nil
}
Can someone tell me why this code wont work ?
The error occur here:
body := strings.NewReader(v.Encode())
rc, ok := body.(io.ReadCloser)
// invalid type assertion: body.(io.ReadCloser) (non-interface type *strings.Reader on left)
However proxy(body io.Reader)
do the same thing but have no error. Why?