Http.Get() - how called?

When I look at package net/http, an example in the package shows that you can do this …

resp, err := http.Get("")

… however, there is no Get() method at the top level. The Get() method which is being called by http.Get() is attached to the Client type.

How come http.Get() can be called like this? Doesn’t Get() need to be attached to a client?

Answered my own question - just read this:

var DefaultClient = &Client{}

DefaultClient is the default Client and is used by Get, Head, and Post.

It’s not super obvious from the godoc overview, but http.Get is a function.

Thank you, Dave Cheney! I was just reading your blog on testing and benchmarking. Thanks for all of your great material. I’m always stoked when you reply to one of my questions. I feel like, well, a feeling akin to meeting someone famous. What, Dave Cheney replied to my question? Awesome. Funny. Alright, thanks.

Since Get() returns an http.Response, you can find it in the Response section of the documentation:

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.