From the course: Learning Go

Unlock this course with a free trial

Join today to access over 24,200 courses taught by industry experts.

Read a text file from the web

Read a text file from the web - Go Tutorial

From the course: Learning Go

Read a text file from the web

- [Instructor] Go has a rich set of tools that let you work easily with web applications and services. The HTTP package lets you make requests and send data to remote hosts and also lets you create HTTP server applications that listen for and respond to requests. In this demonstration, I'll send a request for some data from a remote host. This starting main.go file has a constant named URL and I'll hold down the Command key on Mac or Control on Windows and click it and then click the open button on this dialog and that will open the results of this PHP file. So now I know I can successfully get to that page from my browser and my goal is to download that JSON content to my local development machine. First I'll need some new imports. The first one is called net/http and the other one is io/ioutil. Now I'm going to use a function of the HTTP package, named simply Get. There's also a post function, but I'll just be…

Contents