0PricingLogin
Go Academy · Lesson

Go Modules with go mod

Initializing modules, go.mod, go.sum

What Is a Go Module?

A module is a collection of Go packages with a go.mod file at its root. Modules are the unit of code distribution and versioning in Go:

// go.mod — created with: go mod init github.com/myuser/myapp
module github.com/myuser/myapp

go 1.21

require (
    github.com/gin-gonic/gin v1.9.1
    golang.org/x/sync v0.5.0
)

go mod init

Initialize a new module with go mod init:

# In project directory:
go mod init github.com/myuser/myapp

# This creates go.mod:
# module github.com/myuser/myapp
# go 1.21

# The module path is the canonical import path prefix
# for all packages in this module

All lessons in this course

  1. Packages: Organizing Go Code
  2. Go Modules with go mod
  3. Adding External Dependencies
  4. Internal Packages and Workspaces
← Back to Go Academy