Nobody has started this yet — be first.
Business impact
This breaks the single most common call shape of the service's primary API -- every documented example, and almost certainly every real integration, omits n. Shipping this turns on an immediate, broad outage of /api/v1/check for essentially all normal traffic (a 500, not a graceful denial), the moment it reaches production. Any downstream service that depends on this endpoint for admission control would start failing closed or failing open depending on how it handles a 500 -- either way, an incident, not a degraded edge case.
Problem
Per the README, n in the /api/v1/check request body is "optional, default 1." The overwhelming majority of real calls (and every example in the README) omit it entirely. Those calls are now failing.
Current behavior
curl -s -X POST localhost:8080/api/v1/check -d '{"rule":"free-tier","key":"user-123"}' returns an HTTP 500 with body {"error":"ratelimit: n must be positive"}.
Expected behavior
The same request should behave exactly as if "n": 1 had been sent explicitly -- a normal 200 (or 429 if the key is already over its limit), never a 500.
Steps to reproduce
Build a checkRequest from JSON {"rule":"free-tier","key":"user-123"} (no n field -- Go's JSON decoder leaves req.N at its zero value, 0). Call handleCheck. // got: a 500 response // want: a 200 response, identical to sending "n": 1 explicitly
Why this matters
Omitting n is not an edge case here, it's the default and by far the most common call shape (it's the one used everywhere in the README and in the seeded demo routes' implicit Allow calls). A regression here would 500 out essentially every /api/v1/check request that follows the documented usage until someone starts explicitly sending "n": 1 as a workaround -- exactly the kind of "worked in my testing, breaks for real traffic" bug that a narrow manual test (always sending n explicitly) would miss entirely.
Suggested approach
handleCheck already has logic meant to default a non-positive n to 1 before calling limiter.AllowN. Check the exact boundary condition of that default against what "the zero value of an omitted int64 JSON field" is, and against what AllowN itself considers invalid input (errors.New("ratelimit: n must be positive")).
Acceptance criteria
Verification
go test ./test/ -run TestTask07 -v
Hints (0/2)
Try it without hints first — the reading is the exercise.
Working on this ticket
Work on a branch named for the ticket — that's what you'll submit.
Branch off your fork
Sign in to create it automatically, or do it yourself:
$git checkout -b fix/check-n-defaultingFix it and commit
Meet every acceptance criterion, and add a test that would have caught this.
Push the branch
$git push -u origin fix/check-n-defaultingSubmit it below
Paste your fork URL and the branch name, with a short write-up of the root cause.
Questions
Ask about anything unclear in the ticket — the maintainer and anyone who has solved it can answer. Please don't post full solutions.
Sign in to ask a question or reply.
Sign inhttp://localhost:8080localhost:6380http://localhost:8081curl localhost:8080/healthz
curl localhost:8080/api/v1/rules
curl -s -X POST localhost:8080/api/v1/check -d '{"rule":"free-tier","key":"user-123"}' | jq
No Docker? STORE_BACKEND=memory is the default, so go run ./cmd/server alone (no Redis needed) exercises everything except the Redis-backed code paths.
Work the tickets in tasks/ (ordered easy → hard); each names one Go test in test/:
make test-race # go test -race -count=1 ./...
go test ./test/ -run TestTask01 -v # a single ticket
./test/run_all.sh # all 15, pass/fail summary
Level 1
Fix a bug
Read existing behaviour, correct it.