Join David Gassner for an in-depth discussion in this video Using the exercise files, part of Up and Running with Go.
- This course is accompanied by Exercise Files that you can use to follow along with the demos onscreen. I've copied the exercise files to my desktop, but you can place them anywhere on your hard disk. The Exercise Files are organized by chapter, with one folder for each chapter in the course. Within those folders you will find sub folders for each video, and within those, you will find Go source code files and other assets. Go source code files can be edited in any text editor.
Here I've opened it in TextPad, a common text editor on Windows. But throughout the course, I'll be using a product named Visual Studio Code. It's free, and it works on Windows, Mac and Linux. To work with the Exercise Files in Visual Studio Code, go to the Menu and on Windows, choose File, Open Folder. On Mac, just choose File and then Open. Then navigate to your Exercise Files folder, I've placed it on my desktop, and then, on Windows choose Select Folder and on Mac select Open.
And that will display the Exercise Files directory structure on the left. You can then navigate to any of the files and open them by single-clicking. And you'll see in Visual Studio Code, there's a certain amount of color coding. To run any of these files, after you've installed the Go tools on your computer, right click on the file and then choose Open in Command Prompt, and then type go run and fill in the name of the file. And that should compile and run the source code file.
Most of these source code files can also be run in the Go Playground. To use the Go Playground, copy all the code to the clipboard, then go to a browser. Then go to the Go Playground at play.golang.org. Click in to the editor, select and delete everything. And paste your own custom code into place. Then you should immediately be able to run the code. There are some limitations to this approach, the Go Playground runs in a security sandbox, and it doesn't have access to the web, so you can't make requests to remote hosts.
And there are other limitations that I'll described early in the course having to do with dates and times and working with the file system. But using these exercise files, for the most part you can choose either the Go Playground or you can compile and run your applications locally on your own computer. The exercise files also has a Solutions folder. And the finished versions of all the exercises are here. So if you don't want to type all the code out yourself, you can instead open the solution version of the files and look at the finished code and see how it works.
- Installing Go tools
- Creating and compiling a Go workspace
- Exploring variables, constants, and types
- Storing ordered and unordered values
- Grouping related values in structs
- Programming conditional logic and loops
- Defining and calling functions
- Handling errors
- Working with files
- Creating a simple HTTP server