Read package main, import and func main
Read the structure
package main
import "fmt"
func main() { fmt.Println("Start")}package main identifies the package as an executable program package. A package groups related Go declarations. import "fmt" makes the standard formatting package available under the name fmt. func main() declares the entry function, which takes no arguments and returns no values. Its body is between braces. The line inside calls a function from fmt.
The smallest empty program
This program runs successfully but prints nothing because its body is empty. Imports are only needed when the file uses packages. An ordinary unused import is a compile-time error. In executable packages the entry function must be named main, not Main.
Try it locally
Start with the empty program. Add the fmt import and a Println call that prints Ready.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Getting Started 05: Read package main, import and func main
Check the lesson objective before moving on.
Which declaration identifies an executable package?
What happens if an ordinary fmt import is present but no code uses it?