By Abhijith N M · Reviewed 24 October 2026 · Editorial standards
Fifty lessons ago a program was a file you could not read. Penny now loads and saves real data, has tests for its rules, and answers HTTP requests. The capstone is not a new tutorial: it is the review you do before calling the project finished. You will trace one request, break it on purpose, check the release, and decide whether it is ready to show someone.
| Piece | Where it came from | What proves it works |
|---|---|---|
| Expense model | Step 25 | The struct and its JSON tags |
| Add, list, total | Steps 35-36 | The CLI or curl; go test ./... |
| Persistence | Step 36 | penny.json survives a restart |
| Tests | Steps 38-39 | A failing assertion catches a wrong total |
| HTTP API | Step 46 | GET /health returns {"status":"ok"} |
A review starts by following a request from the outside in. The diagram below has three scenarios: a list, a create, and a bad request. Switch between them and notice that the same four lanes explain all three.
A release review is mostly an attempt to make the program fail. Run each case below against your finished Penny and write down the status code or error you see. If the behaviour is different, fix it before you ship.
| What you do | What should happen | What you are checking |
|---|---|---|
| Stop the server, start it again, list expenses | The same expenses return | Persistence still works |
Replace penny.json with not json and restart | Penny refuses to start with a wrapped load error | Corrupt data is reported, not ignored |
POST with {"description":"","cents":-1} | 400 with a clear JSON error | Input validation |
GET /expenses/9999 | 404 with expense not found | Unknown ID path |
| Start a second server while the first is running | bind: address already in use | Port conflict is visible, not silent |
Every project needs one test that would have caught a real regression. For Penny, the rule that matters most is what happens when there is no data file yet: the store must return an empty list, not crash. This listing is a complete test for that rule. Save it next to your store code and run go test ./....
// ==== file: store.go ====
package main
import (
"encoding/json"
"errors"
"os"
)
// Expense is one row in Penny's list. Money is stored in integer cents.
type Expense struct {
ID int `json:"id"`
Description string `json:"description"`
Cents int `json:"cents"`
Category string `json:"category"`
}
// loadExpenses treats a missing file as "no expenses yet".
func loadExpenses(path string) ([]Expense, error) {
data, err := os.ReadFile(path)
if errors.Is(err, os.ErrNotExist) {
return []Expense{}, nil
}
if err != nil {
return nil, err
}
var expenses []Expense
if err := json.Unmarshal(data, &expenses); err != nil {
return nil, err
}
return expenses, nil
}
// ==== file: store_test.go ====
package main
import "testing"
func TestLoadMissingFileReturnsEmptyList(t *testing.T) {
expenses, err := loadExpenses("does-not-exist.json")
if err != nil {
t.Fatalf("expected no error for a missing file, got %v", err)
}
if len(expenses) != 0 {
t.Fatalf("expected no expenses, got %d", len(expenses))
}
}Run it once with the test, then break the behaviour on purpose: change the missing-file branch to return an error. The test should now fail and tell you exactly which expectation broke. Revert the change. That failure is the value of the test.
Read this list honestly. A demo is finished when every line is true, not when the program mostly works.
| Check | How to prove it |
|---|---|
gofmt -l . prints nothing | No formatting drift |
go vet ./... and go test ./... pass | Code is checked and the release test passes |
go build -o penny . produces a binary | The project can be shipped |
GET /health returns {"status":"ok"} | The server starts and routes |
| Add, restart, list | The data file round-trips |
| README explains run, data and tests | Someone else can use it |
| You can explain every line of main.go and store.go | You built it, not just copied it |
Start the server, then run these commands in a second terminal. The responses are what a correct Penny 1.0 returns.
curl -s http://localhost:8080/health
{"status":"ok"}
curl -s -X POST http://localhost:8080/expenses \
-H "Content-Type: application/json" \
-d '{"description":"coffee","cents":450,"category":"food"}'
{"id":1,"description":"coffee","cents":450,"category":"food"}
curl -s http://localhost:8080/expenses
[{"id":1,"description":"coffee","cents":450,"category":"food"}]
curl -s http://localhost:8080/expenses/99
{"error":"expense not found"}The course ends here, but the project does not have to. These extensions reuse what you already know and add one new idea at a time:
sum endpoint that returns the total in cents and formatted dollars.category query parameter on the list endpoint, filtered with a loop.DELETE /expenses/{id} endpoint that removes an entry and saves the file.go test for each handler using net/http/httptest.-addr flag so the port comes from the command line instead of a constant.Key takeaways
A capstone is a review: trace the request, try to break it, then check the release.
The mutex, validation and error responses are what make the API safe to run.
Every feature earns its place by surviving a restart and a test.
A README is part of the product, not an optional extra.
Written and edited by the nexGenCoders team. Spotted a mistake? Tell us and we will fix it.
Don't lose this lesson
Create a free account to save your progress, keep your streak, and work toward a shareable certificate.