Why and How of Go
Where is Go Exactly Used?
Go dominates the Cloud and Backend world. If you interact with the cloud, you are using Go.
- Infrastructure & Tools: Docker, Kubernetes, Terraform, and Prometheus were all written in Go.
- Microservices & APIs: Companies like Uber, Twitch, and Netflix use Go for their heavy-lifting backend services because it handles thousands of concurrent requests smoothly without eating up server memory.
- CLI Tools: Because Go is so fast to start up, it's perfect for Command Line Interfaces (like the GitHub CLI).
Go is compiled and statically typed. It might take a few extra seconds to write the types, but the compiler catches most of your errors before the code ever runs.
Go compiles your entire application into a single, standalone binary executable file. It includes everything it needs to run. You just drop that one file onto an empty Linux server (or into a tiny "scratch" Docker container), execute it, and it runs instantly. No runtime or dependencies needed on the server!
Project Structure & Starting a Project
In Go, we use Modules to track our project.
Standard workflow to start a new project from your terminal:
Initialize the module
go mod init github.com/yourusername/myapp
This creates a go.mod file, which is exactly like Python's requirements.txt or Node's package.json.
No.
- You can use any name for local development.
- GitHub URL is only needed if you plan to publish or share the module.
Why:
- Go uses the module name as a download path.
- Tools like
go getlook for that exact URL online. - If it’s not a real/accessible path, others can’t install your code.
- Locally → Works fine. Go only reads
go.mod. - After pushing → Problems start.
Why:
go getuses the module path as a URL.- If names don’t match → download fails or errors.
Fix:
- Update
go.modto match your actual repo URL.
Create your entry point
Create a file named main.go.
Run the code (for development):
go run main.go
This compiles and runs your code on the fly.
Build the code (for production):
go build
This spits out the magical standalone binary file we talked about.
go build (without arguments) builds the entire module/package defined in go.mod.If you haven’t initialized a module, Go won’t know what to build and may throw an error.
You can also build a specific file directly:
go build main.go
This compiles only that file and does not require a module.
Key idea:
go build→ builds the project (module/package)go build <file.go>→ builds a single file