I am studying http source codes of Golang, I found this
func NewRequestWithContext(ctx context.Context, method, url string, body io.Reader) (*Request, error) {
...
rc, ok := body.(io.ReadCloser)
...
}
but this body is nil, it is passed in the following way
func NewRequest(method, url string, body io.Reader) (*Request, error) {
return NewRequestWithContext(context.Background(), method, url, body)
}
func (c *Client) Get(url string) (resp *Response, err error) {
req, err := NewRequest("GET", url, nil)
if err != nil {
return nil, err
}
return c.Do(req)
}
Function Get passes nil to function NewRequest,
function NewRequest passes this nil to function NewRequestWithContext,
then function NewRequestWithContext use nil to call nil.(io.ReadCloser), why does not it cause panic?