GOing into the deep end with Go
·2 mins
Terrible pun, sorry-not-sorry.
This weekend I decided to make the jump and start learning golang. I haven’t really done much with a compiled language since college (not counting Java, even though it’s compiled to byte-code).
Below are some things I discovered while setting up my environment, using VS Code for developing:
- If you’re using a Mac, make sure you have xcode installed as well as the command-line tools (
xcode-select --install
). I had them installed previously, but since upgrading to Mojave I didn’t reinstall some tools. Not doing this will give you this error:could not launch process: stub exited while attempting to connect: signal: illegal instruction
- Follow the standard practice in Go by creating a centralized go directory and creating a GOPATH environment variable. For me, I did
$HOME/dev/go
for myGOPATH
and added this to my.bash_profile
- With VSCode, install the Go plugin and create a simple go file, like so:
package main
import "fmt"
func main() {
fmt.Println("hello world")
}
- With your simple code, you should see a little pop-up to install Golang tooling for VSCode. Tell VSCode to install everything.
- From the Command Palette, run
Go: Install/Update Tools
and selectdlv
for updating. - Finally, go back to the Command Palette and run
Debug: Open launch.json
. This should create a basic debugger profile
At this point, you should have a working environment to start learning Go. Hope this helps!
References: