Demo project¶
A small Go module that exercises most of the topics covered in this folder:
09-demo-project/
├── go.mod # module manifest
├── main.go # package main — the program entrypoint
├── counter/
│ ├── counter.go # public package, importable from outside
│ ├── counter_test.go # internal tests + benchmark
│ └── testdata/ # ignored by the build, used by tests
│ ├── alice.txt
│ └── lorem.txt
└── internal/
└── workpool/
└── workpool.go # only importable from inside this module
What each part demonstrates:
go.mod— module path isexample.com/demo; created withgo mod init.main.go—package mainproduces an executable. It imports bothcounter(sibling package) and uses the runtime tracer.counter/— an ordinary package, importable asexample.com/demo/counter.counter/counter_test.go— same-package tests (can see unexported symbols), plus aBenchmarkCountConcurrent.counter/testdata/— thegotool refuses to compile anything insidetestdata/, so fixtures live here safely.internal/workpool/— Go's compiler enforces thatexample.com/demo/internal/workpoolcan only be imported by packages rooted atexample.com/demo. If you copied this module to another path, external code could not reachworkpool.
Running it¶
From this directory:
Expected output (numbers approximate):
This also writes trace.out.
Running the tests¶
To run the benchmark:
Viewing the trace¶
After go run . has produced trace.out:
This starts a local web server and prints a URL like http://127.0.0.1:NNNNN/.... Open it in a browser and explore:
- View trace — the goroutine timeline.
- Goroutine analysis — what each goroutine spent its time on.
- Sync / scheduler blocking profiles — where goroutines were waiting.
Press Ctrl-C in the terminal to stop the viewer.
Files relating back to the conspect¶
| Topic | Conspect file | Where you see it here |
|---|---|---|
go.mod directives |
04-go-file-types.md | go.mod |
_test.go, testdata/ |
04-go-file-types.md | counter/counter_test.go, counter/testdata/ |
internal/ rule |
05-special-folders.md | internal/workpool/ |
runtime/trace and go tool trace |
03-go-tool-trace.md | main.go's trace.Start / trace.Stop, plus trace.out |
go run, go test, go build |
02-go-subcommands.md | the commands above |