2.7 Editor Setup: VS Code with gopls, GoLand

Right, let’s get your editor sorted. This isn’t just about typing code; it’s about creating a feedback loop so tight you’ll feel like the compiler is whispering its secrets directly into your ear. We’re going to set up two of the best options: the free, utterly dominant VS Code, and the paid, Go-native powerhouse, GoLand. Both are excellent. Your choice here is between a brilliantly customized Swiss Army knife and a purpose-built scalpel.

2.6 go env: Inspecting the Go Environment

Right, so you’ve got Go installed. You ran the installer, maybe you even compiled it from source to feel like a real wizard. But how do you know it’s set up correctly? How do you see what Go itself thinks about its own world? You ask it. Politely. With the go env command. Think of go env as your backstage pass to the Go opera. It shows you all the environmental variables and paths that the go tool is using to make decisions. This isn’t just a list of boring settings; it’s the very DNA of your current Go workspace. When something goes weird—and it will—this is your first stop for forensic evidence.

2.5 go get and go install: Adding and Installing Packages

Right, so you want to add a third-party package to your project. Welcome to the fun part. You’ve got two main tools for the job: go get and go install. They seem similar, but they serve two very different masters, and confusing them is a rite of passage for every Go developer. Let’s demystify them. The Old Way vs. The New Way First, a quick history lesson because context is everything. Before Go 1.11 and the advent of modules, go get was the Swiss Army knife for fetching and building and installing packages. It was a bit of a mess. The designers, in their infinite wisdom (and I mean that mostly sincerely), decided to untangle this with the introduction of modules.

2.4 go mod: Initializing and Managing Modules

Right, let’s get to the part that saves you from the dependency hell your predecessors in other languages still occasionally visit. Forget GOPATH. Seriously, forget its address, its birthday, everything. We’re in the module era now, and go mod is your new best friend. It’s the Go team’s official answer to the question, “How do I manage dependencies without losing my mind?” And for the most part, it’s brilliantly simple.

2.3 The go Command: build, run, test, fmt, vet, doc

Right, let’s get our hands dirty. You’ve got Go installed, which means you also got its primary delivery mechanism: the go command. This isn’t just a compiler; it’s your entire project manager, build system, dependency fetcher, and code quality enforcer, all rolled into one brutally efficient binary. Forget sprawling XML configuration files or a tower of bash scripts. The go command is the benevolent dictator of your workflow, and it has Opinions.

2.2 GOROOT, GOPATH, and GOBIN Explained

Right, let’s talk about the three amigos: GOROOT, GOPATH, and GOBIN. If you’re coming from a language like Python or Node.js, this setup might feel a bit… opinionated. That’s because it is. The Go team had a very specific, and initially very successful, idea about how to organize your entire universe of Go code. We’ll get into why that model started to creak and what’s changed, but first, you need to understand the original blueprint. Trust me, this historical baggage is still in your attic, and you need to know about it to avoid the cobwebs.

2.1 Downloading and Installing Go: Official Installer and Package Managers

Right, let’s get you set up with a working Go installation. This isn’t brain surgery, but there are a few ways to do it and a couple of potholes I’d like to steer you around. The goal here is to get a clean, maintainable, and standard installation. We’re not trying to impress anyone with our custom-built-from-source prowess. Yet. The Official Installer: The Path of Least Resistance For 99% of you, especially if you’re on Windows or macOS, the official installers from golang.org/dl are the way to go. They Just Work™. You download a file, click through an installer (or untar a archive), and you’re basically done. The crucial thing these installers do, which you might not appreciate until you’ve manually borked it, is they set up your entire workspace with the correct permissions and they put everything in the one true place Go expects it to be.

— joke —

...