All lessons

Your First Program

6 min · Go

Write and run your very first Go program, right here on the page.

Go · Your First Program0/5 cleared

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.

You
Binary Treant

Loading editor...

Ln 1, Col 1Spaces: 4
Sign up to fightTarget output: Hello, World!