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
~/work
folder and thesrc
folder beneath it - In the
~/.bash_profile
file, add the following lines:
export GOPATH=$HOME/work
export PATH=$PATH:$GOPATH/bin
- Create the
C:\work
folder and thesrc
folder beneath it
The installer should have added the appropriate environment variables, but just in case:
-
Add
GOPATH
environment variable- Go to the
Control Panel -> System
and Click onAdvanced system settings
- In the dialog, click the
Advanced
tab - Then click on the
Environment Variables
button - Under
System Variables
, click theNew
button - Enter
GOPATH
for the name, and path to yourwork
folder - 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 + P
on a Mac, orCtrl + P
on 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 P
on a Mac, orCtrl + Shift + P
on Windows) - Type
Go Install
. The optionGo: Install/Update Tools
should be visible. - Select this option, and wait while all of the Go tools are installed