From the course: Code Clinic: Go

Unlock this course with a free trial

Join today to access over 22,400 courses taught by industry experts.

Retrieving files using HTTP

Retrieving files using HTTP - Go Tutorial

From the course: Code Clinic: Go

Retrieving files using HTTP

- So here is the last step in our solve, and the very last step in our solve is to get our data programmatically. And so we're going to use, from the http package, the Get function, and that's going to allow us to go get the data at a certain URL. When we get the data at a certain URL, it's going to give us a response. When we have a response, attached to that response, we have a Body. So if we look at http.Get, I'm going to hold down cmd and go into the standard library and look at that code, takes in that url, gives us a Response and an error, and if we look at the Response, the Response is a struct with these different fields, including a Body. So when we get that Response, we have a Body, and we pass it in to ReadAll. Well what is it that ReadAll takes? If I click on that, I see that ReadAll takes an io.Reader, so something that implements the Reader interface. Well, it must be that response Body implements the Reader interface, but can we prove that? So here's a little bit of a…

Contents