Skip to content

Your first program

Every Go program is composed of packages. A package named main is special: it defines an executable program. The entry point is a function named main with no parameters and no return values.

package main // Package declaration
import "fmt" // Import statement (standard library)
func main() { // Entry point function
fmt.Println("Hello, World") // Statement
}
  • package main – Declares that this file belongs to the main package.
  • import "fmt" – Imports the fmt package for formatted I/O.
  • func main() – The program starts here. No arguments, no returns.
  • fmt.Println – Prints a line to standard output.

Save the code as main.go, then in a terminal:

Terminal window
go run main.go

Create a file main.go with the content below.

package main
import "fmt"
func main() {
fmt.Println("Hello, World")
}
Terminal window
Hello, World