Your First Go Program
Create, run, and understand a basic Go program.
Learning objective: Write and run your first Go program using package main and func main.
Creating main.go
Create a file named main.go. A basic executable Go program begins with package main.
Importing Packages
The import statement lets your program use features from Go's standard library. The fmt package is used to print output.
The main Function
The main function is the starting point of a Go program. When you run the program, Go begins execution inside func main.
Example Code
Create or update your Go file, then run the program using go run main.go.
package main
import "fmt"
func main() {
fmt.Println("Hello, Go!")
}
Key points to remember
- Go is case-sensitive.
- Every opening brace must have a matching closing brace.
- Run a simple file with go run main.go.
Practice Exercises
- Create main.go.
- Print Hello, Go! to the screen.
- Modify the program to print three different lines.
Continue Learning
After this lesson, continue to the next lesson or explore related tutorials on VisualStudioTutor.com.