Go - First Program
Beginner 10/10
Teacher 10/10
Architect 10/10
Minimal Program
- Create a folder and module:
mkdir hello-go && cd hello-go go mod init example.com/hello - Create
main.go:package main import "fmt" func main(){ fmt.Println("First Go Program") } - Run it:
go run . # Expected output: # First Go Program
Windows tip: The commands above also work in PowerShell. Use
mkdir and cd the same way. Run go commands from a new PowerShell window after installing Go.
Run vs Build
go run .compiles to a temp binary and runs it.go buildcreates a binary in the current directory.
Common errors
go: no go files listed: you’re not in the folder withmain.goor the file is named differently.package mainmissing: executable programs must usepackage mainand definefunc main().
Practice
- Print your name and today’s date on separate lines.
- Change the message and rebuild with
go build, then run the binary.
Try:
- Modify the message; re-run quickly with
go run .. - Build the binary and run it directly.