Go Program Structure, Packages, main() & Compilation Model
1Concept
Go programs begin in package main inside func main(). Go compiles directly to a standalone, statically linked machine binary with no external runtime dependencies.
2Architecture Diagram
[main.go] ──► (go build) ──► [Single Static Binary (~15MB with embedded runtime & GC)]
3Code Example
Stage 0 Language Foundations
package main
import (
"fmt"
"runtime"
)
func main() {
fmt.Println("=== Go 1.22 Runtime Engine ===")
fmt.Printf("Go Version: %s\n", runtime.Version())
fmt.Printf("OS/Arch: %s/%s\n", runtime.GOOS, runtime.GOARCH)
fmt.Printf("Active CPUs: %d\n", runtime.NumCPU())
}4Expected Output
=== Go 1.22 Runtime Engine === Go Version: go1.22.2 OS/Arch: windows/amd64 Active CPUs: 8
5Key Takeaways
- ✓Every Go executable requires 'package main' and 'func main()'.
- ✓Go binaries are statically linked, making Docker images lightweight (scratch container).
- ✓Unused imports or variables cause compile-time errors in Go.