The first step is to download and install Go here
The most important part of installing Go is setting up the $GOPATH environment variable. You can set this variable to whatever folder you wish, but it must have a child src folder beneath it. For the purposes of this course, we will use the folder work.
- Create the
~/workfolder and thesrcfolder beneath it - In the
~/.bash_profilefile, add the following lines:
export GOPATH=$HOME/work
export PATH=$PATH:$GOPATH/bin
- Create the
C:\workfolder and thesrcfolder beneath it
The installer should have added the appropriate environment variables, but just in case:
-
Add
GOPATHenvironment variable- Go to the
Control Panel -> Systemand Click onAdvanced system settings - In the dialog, click the
Advancedtab - Then click on the
Environment Variablesbutton - Under
System Variables, click theNewbutton - Enter
GOPATHfor the name, and path to yourworkfolder - Click
OK
- Go to the
The workspace is defined first by the location pointed to by GOPATH. Beneath the src folder is where projects are located.
Usually, to conform to best practices, beneath the src folder are the names of the organizations where the code is stored. Typically, these are SCMs, like github.com.
Beneath that folder is the name of the account owner for the SCM.
And finally, the last folder is the Go project folder.
$HOME/work // The main source folder (GOPATH)
|
|-- 📂 src
|
|-- 📂 bitbucket.org
|-- 📂 nordstrom
|-- order-guard // Location of order-guard repo
|-- 📂 github.com
|-- 📂 andrewlader
|-- go-course // Location of go-course work
The easiest way to verify that Go was installed properly is to perform the following command from a terminal window:
go env
Look at the ouput and ensure that the GOPATH environment variable is set appropriately.
For this course, the IDE of choice is Visual Studio Code, which can be downloaded from here
Once this has been installed, install the Go Extension plugin using the following steps. Make sure you pick the one with over 900K downloads.
- Launch VS Code Quick Open (
Command + Pon a Mac, orCtrl + Pon a Windows machine) - Type the following command and press
Enter
ext install Go
You may be told to reload VS Code.
Once the plugin has been installed, it is time to install some additional Go tools to help with editing.
- Launch the Command Palette (
Command + Shift Pon a Mac, orCtrl + Shift + Pon Windows) - Type
Go Install. The optionGo: Install/Update Toolsshould be visible. - Select this option, and wait while all of the Go tools are installed
