Your First Program
6 min · Go
Write and run your very first Go program, right here on the page.
Enemy 1 of 5
Packages, imports, and func main
Every Go file starts by declaring which package it belongs to — package main at the top is special: it marks this file as a runnable program (as opposed to a library other code imports), and it must contain a function named main, which is where execution begins the moment you run the program.
import "fmt" brings in the fmt ("format") package, Go's standard toolkit for printing and formatting text. Go is strict about unused imports — if you import a package and never use anything from it, the compiler refuses to build your program, which keeps codebases tidy but can surprise newcomers the first time it happens.
Go was designed at Google specifically to compile fast and read simply — notice there's far less boilerplate here than in C++ or C#: no using namespace, no class wrapper, just package, import, and func main.
Loading editor...