Fundamentals

Project Structure

Learn about the project structure of Go.

In Go, we use Modules to track our project.

Standard workflow to start a new project from your terminal:

Initialize the module

Terminal
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.

Always make the module name in your go.mod file match the exact URL where the code is actually hosted.

Create your entry point

Create a file named main.go.

Run the code (for development):

Terminal
go run main.go

This compiles and runs your code on the fly.

Build the code (for production):

Terminal
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:

Terminal
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
Copyright © 2026