← Course map

GO LEARNING PATH · 14 LESSONS

Standard library patterns

io.Reader and io.Writer, encoding/json, and testing without a framework.

  1. Two interfaces, one method each

    Write a function that works on a file, a string and a test buffer.

    3 min · Worked lesson

  2. Struct tags are the JSON schema

    Control field names, omit empties, and know what unmarshalling leaves untouched.

    3 min · Prediction challenge

  3. JSON v2: migrate behavior, not just imports

    Compare null, empty and omitted JSON values before changing a public API.

    3 min · Worked lesson

  4. A Duration is a number of nanoseconds with a type

    Write a timeout without wondering what unit it is in.

    3 min · Prediction challenge

  5. Sorting by whatever you like

    Sort a slice of structs by two keys.

    3 min · Worked lesson

  6. Every blocking call should take a context

    Make a function that waits stop waiting when told to.

    3 min · Worked lesson

  7. http.Handler is one method, like Reader

    Serve /hello from an in-memory request, with no listen.

    3 min · Worked lesson

  8. strconv is how text becomes a number

    Parse a port with Atoi and reject anything outside 1…65535.

    3 min · Worked lesson

  9. image.Image is three methods, not a file

    Implement a solid-colour image the standard library will accept.

    3 min · Worked lesson

  10. Borrow bytes briefly; copy before their owner changes

    Trace bytes.Buffer and Scanner views, then make retained results independent at a lifetime boundary.

    3 min · Worked lesson

  11. JSON presence: omitted, zero and null are different states

    Choose omitempty, omitzero and request presence models from the endpoint contract.

    3 min · Worked lesson

  12. Strict JSON input: reject ambiguity before side effects

    Separate JSON syntax acceptance, unknown-member policy and domain validation.

    3 min · Worked lesson

  13. Timers and cancellation: versioned semantics still need a single owner

    Explain Stop/Reset behavior, timer ownership and why select is not a priority statement.

    3 min · Worked lesson

  14. Outgoing HTTP: reuse the client and bound the response, not just the dial

    Own the client lifetime, close bodies and classify HTTP status separately from transport failure.

    3 min · Worked lesson