Skip to content

Day 042 — Week 2 Review + Recall

Month 2 · Week 2 · ⬅ Day 041 · Day 043 ➡ · Journal index

🎯 Learning Objective

Consolidate this week's stdlib service-building toolkit — encoding/json, time, net/http client, context, and log/slog — with closed-book recall, then write the formal weekly review.

📚 Topics

  • Recap: JSON (un)marshaling & custom marshalers, time/durations/timers, http client, context deadlines/cancellation, slog

📖 Reading / Sources

📝 Notes

  • This is a review day — the full writeup, re-quiz, action items, and metrics live in the week review file: week-2-review.md.
  • One-line theme: the standard library is enough to build a real networked service — encode data (json), keep time/timeouts (time), call other services (http), thread cancellation through everything (context), and observe it (slog).
  • The thread connecting the week: a request carries a context deadline → an http.Client makes a context-bound call → the body is encoding/json → failures and latencies are reported with log/slog → all timing measured with time.

💻 Code Examples

// The week in one flow: deadline -> context-bound request -> JSON -> log.
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second) // time + context
defer cancel()
req, _ := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)     // http client
resp, err := client.Do(req)
if err != nil {
    logger.Error("fetch failed", slog.Any("err", err)) // slog
    return err
}
defer resp.Body.Close()
var v Payload
_ = json.NewDecoder(resp.Body).Decode(&v) // encoding/json

🏋️ Exercises / Practice

Exercise Status Link
Re-run all Week 2 tests go test ./exercises/month-02/week-2/...

🐛 Mistakes Made

  • (Review day) Consolidated this week's mistakes into the weekly review's "Weaknesses" section.

❓ Open Questions

  • Carried into the weekly review's re-quiz and next-week goals.

🧠 Active Recall (answer without looking)

  1. Q: A function takes ctx with a 1 s timeout and calls time.Sleep(10 * time.Second). When does it return?

    A After the full 10 seconds — `time.Sleep` ignores the context. To honor the deadline it must `select` on `ctx.Done()` or call a context-aware API. The context only *signals*; it can't preempt code.

  2. Q: Two stdlib traps from this week that silently produce wrong/empty results?

    A A value-receiver `UnmarshalJSON` (ignored, field stays zero), and an odd number of loose `slog` key/value args (yields `!BADKEY`). Also worth recalling: `Unmarshal` into a non-pointer, and not closing `resp.Body`.

🪶 Feynman Reflection

The week turned the standard library into a service starter kit: I can describe data on the wire (json with full custom control), measure and bound time (durations, layouts, timers), call out to other services safely (http client with timeouts and closed bodies), carry a single "stop" signal through the whole call tree (context), and narrate what happened in machine-readable lines (slog).

🕳️ Knowledge Gaps

  • See the weekly review for the consolidated gap list heading into Week 3 (testing & tooling deep dive).

✅ Summary

Week 2 of Month 2 is consolidated: I can build, call, time, cancel, and log a small networked service using only the standard library. Details in the weekly review.

⏭️ Next Steps / Prep for Tomorrow


Time spent Difficulty Confidence
90 min 🟦⬜⬜⬜⬜ 🟦🟦🟦🟦⬜

Suggested commit: docs(journal): month 2 week 2 review and recall (day 042)