GoGo · Lesson 1 of 8
Hello, World!
Go's Hello World is famously minimal. Package declaration, one import, one function. That's the whole language in microcosm.
Every Go file starts with a package declaration. The main package is the entry point for executables. fmt is the standard library package for formatted I/O. Every Go program that prints something will import fmt.
Save as hello.go and run with go run hello.go. To compile a binary: go build hello.go, then ./hello. Go compiles fast — fast enough that go run feels instant.
◆ Note
Go enforces that all imports are used. If you import a package and don't use it, your code won't compile. Same for declared variables — unused variables are compile errors. Go takes "clean code" literally.
Go enforces that all imports are used. If you import a package and don't use it, your code won't compile. Same for declared variables — unused variables are compile errors. Go takes "clean code" literally.