How Go Packages Work

A Complete Guide

Go packages group related source files under a single name to organize code and enable sharing across modules.

Go packages are logical groupings of source files that share a single package name, enabling code organization and reuse across modules. You define a package by placing .go files in the same directory and declaring the same package name at the top of each file. To use a package from another module, import it using its full module path in your source code.

package main

import "fmt"

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