go

language

banner

Packages

People run in packs because they don’t feel safe alone.
I run alone because I don’t feel safe in packs.
Muhammad Ali

The primary unit of organization in a Go program is the package. A package consists of one or more files that reside in the same folder. A file consists of import, constant, variable, type and function declarations. It is conventional to name the folder containing the package with the name of the package.

Packages export identifiers that start in uppercase. Identifiers in lowercase are visible only inside the package block. There is no need for scope specifiers. Simple!

Packages are organized hierarchically inside a folder structure. The identifier of a lower level package is — conventionally — the path from the top-level package to the lower level package separated by forward slashes.

The package name main is special and the function main() in that package denotes the beginning point of execution in that program.

Example

// hello.go

package main

import "fmt"

func main() {
    fmt.Println("hello, world!")
}

Here, fmt is the standard formatter package. Notice that the Println() function — exported by the fmt package — starts with an uppercase letter.