So you’ve installed Go, written your first “Hello World,” and maybe even experimented with a few functions.
Now comes the part that often confuses beginners — how do you structure a real Go project?
That’s where Go Modules come in.
In older Go versions, developers had to depend on GOPATH, and everything lived inside a single directory.
Thankfully, things are much simpler today. Modern Go development uses Go Modules, a powerful dependency-management system that keeps your projects clean, portable, and version-controlled.
Let’s break it down in the simplest way possible.
What Are Go Modules?
A Go module is essentially your project folder — plus a file that says:
- What is your project is called
- which packages it uses
- which versions they depend on
- This file is called go.mod.
Whenever your Go project grows beyond a single file, Go Modules help you:
- track dependencies
- switch Go versions
- build the project consistently on any machine
- avoid “it works on my laptop” problems
Creating Your First Go Module
Open your terminal and navigate to an empty folder:
- - mkdir yourProjectName
- - cd yourProjectName
Now initialize a module:
- go mod init yourProjectName
This command creates a go.mod file.
Inside it, you’ll see something like:
module yourProjectName
go 1.22
That’s it — your project is now a Go module.
Top comments (0)