Homework
Homework — your app stops forgetting
The last homework before the finale — YOUR app stops forgetting:
- Add JSON tags to your struct fields.
- Write
saveItemsandloadItemsfor your type (names may differ — what matters is the same shape: returningerror, missing file → empty list). - Load on startup, save on quit via
q. - Replace
Scanlnwithbufio+readLine— test with a value that contains a space.
Required tests (all three are part of the submission):
- The restart test: add 2–3 records, quit, run again — the list is back.
- The first-run test: delete your
.jsonfile and run — the app shows an empty list and does NOT crash. - The cleanliness test (the lesson 8 habit):
gofmt -l .andgo vet ./...— both silent.
To submit: the code + a transcript of all three tests + the contents of your .json file.
Tip. Stop and look around: structs, functions, loops, validation, slices, files — every brick is laid. One tool is still missing from your box: the pointer (
*Item) — changing a record IN PLACE, without the index trick around copies. Remember the copy gotchas from lessons 3 and 7? The final project gives them their definitive answer — and there, everything you built across 10 lessons assembles into one program.