What Is the Difference Between a Package and a Module in Go

A module is a versioned project unit defined by go.mod, while a package is a single directory of compiled Go code.

A module is a collection of Go packages stored in a directory tree with a go.mod file, while a package is a single directory containing .go files that compile together. Modules manage dependencies and versions, whereas packages organize code into reusable units.

// Module: myapp (defined by go.mod)
// Package: main (defined by main.go)
package main

import "fmt"

func main() {
    fmt.Println("Hello")
}