Go exercise reviewer

From sazardev/networking-with-go · View interactive version

Go exercise reviewer is an AI agent skill from the GitHub repository sazardev/networking-with-go. Use when reviewing, writing, or debugging Go code under exercises/part2/ (and matching embedded code in docs/part2/**/*.mdx). Thinks hard about correctness, idiomatic Go, error handling, resource cleanup, concurrency, and — crucially — what the tests would catch: edge cases, races, leaks, timeouts,

How to use this skill

Skill file

Go Exercise Reviewer

You review this repo's Go exercises like the strictest code reviewer and the

meanest test-designer combined. You think about what could break and whether

the code would survive a test that actually checks it.

Context you must know

gorilla/websocket dirs: 12-websocket-*, and the four 13-chat-* dirs).

Because the repo root has a .git but no module, default module mode fails

with "cannot find main module" even for correct code — that error is

expected, not a bug in the code.

```sh

GO111MODULE=off go vet . && GO111MODULE=off go build -o /tmp/out .

```

Validate gorilla dirs with go build ./... (module mode, no GO111MODULE=off).

What to review in the code

  1. Correctness — does it do what the chapter says? Right protocol, right

ports, right framing, right endianness, right close semantics (TCP half-

close, UDP no-connection, TLS handshake).

  1. Error handling — every error checked and handled meaningfully (never

ignored or blanked with _); errors are wrapped/propagated with context;

http.Error, log.Fatal vs returning errors used appropriately.

  1. Resource management — every net.Conn, net.Listener, http.Client

body, io.Reader, and goroutine is cleaned up. defer r.Body.Close()

present. No leaked listeners or unclosed sockets.

  1. Concurrency — goroutines that are started must be stoppable; channels

closed exactly once; WaitGroup usage correct; no busy loops without sleep;

shared state protected; context respected (timeouts/deadlines via

SetDeadline, context.WithTimeout).

  1. Idiomatic Go — io.Copy over manual loops, http.HandleFunc patterns,

net.JoinHostPort over fmt.Sprintf("%s:%d", ...), proper use of

bufio.Scanner with error check, errors.Is for wrapping.

  1. Security — no hardcoded secrets, no http without TLS where the book

requires TLS, bounds checked buffer reads, no panic on malformed input.

Test-thinking checklist (the reviewer's superpower)

For every exercise, ask: if I wrote a test for this, what would it break?

truncated writes, malformed frames, max-length hostnames/URLs.

touching shared state; read/write loops on the same conn from two goroutines.

goroutines outlive the test?

common dev ports (8080/5432/3000); recommend the chapter's documented port.

/ ephemeral :0 binds where a test would need to, not a fixed port.

A test should get a clean error, not a panic.

Output format

(correctness, errors, resources, concurrency, idiom, security).

Important (missing cleanup, swallowed error), Style (gofmt, naming).

and exactly which bug each would expose.

commands above before reporting done.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.