Hello, World
The smallest Go program: package main, func main() and fmt.Println.
Runs in Zerethon IDE · Go 1.27
Official Go documentation ↗
A Go program is package main with a func main(). The program starts in main and ends when main returns. Everything you use from the standard library is imported by name.
main.go
package main
import "fmt"
func main() {
fmt.Println("Hello, World!")
fmt.Println("Sum:", 2+3)
fmt.Printf("%s-%s!\n", "a", "b")
}
Output
Hello, World! Sum: 5 a-b!
fmt.Printlnseparates its arguments with a space and ends with a newline;fmt.Printfprints exactly the format you give it (%stext,%dinteger,%vany value).- Braces are required, and the opening
{must be on the same line asfunc,iforfor. - Every import must be used: an unused import is a compile error, not a warning.