Skip to content

feat: add Skip middleware; improve docs#56

Open
lrstanley wants to merge 1 commit intogo-chi:masterfrom
lrstanley:feature/skip-misc-cleanup
Open

feat: add Skip middleware; improve docs#56
lrstanley wants to merge 1 commit intogo-chi:masterfrom
lrstanley:feature/skip-misc-cleanup

Conversation

@lrstanley
Copy link
Copy Markdown

@lrstanley lrstanley commented Mar 29, 2026

Changes in this PR

  • Added httprate.Skip, which is a simpler (and more obvious) shorthand for setting the increment to 0 in context, to have endpoints designed to let API users see what their rate limit is (specifically when the key isn't endpoint specific, for example), without incrementing it. i.e., an endpoint that still sets the associated headers, without incrementing the rate limit.
    • Added test that covers this new flow.
  • Added documentation/comments to most functions, as there were almost none before.
    • Uses the newer linkable syntax for inter-package and external-package types (in most IDEs, allows hovering over the function/type, and making those type references clickable).
  • Adjusted some of the logic to be modernized for Go 1.24 -- loop vars, range over int, time.Time.Equals for more accurate time equality checks, etc.
  • Fixed odd formatting of the go.mod file.
  • More stdlib constant usage vs generic ints, e.g. 429 vs http.StatusTooManyRequests.

Notes to Reviewer

All tests pass locally with:

go test -v -race -count 10 -cpu 1,4 ./...

Signed-off-by: Liam Stanley <liam@liam.sh>
@github-actions
Copy link
Copy Markdown

Benchmark Results

goos: linux
goarch: amd64
pkg: github.com/go-chi/httprate
cpu: AMD EPYC 7763 64-Core Processor                
               │ master.txt  │            pr.txt             │
               │   sec/op    │   sec/op     vs base          │
LocalCounter-4   32.57m ± 4%   32.84m ± 1%  ~ (p=0.529 n=10)

               │  master.txt  │             pr.txt             │
               │     B/op     │     B/op      vs base          │
LocalCounter-4   2.845Mi ± 0%   2.847Mi ± 0%  ~ (p=0.280 n=10)

               │ master.txt  │            pr.txt             │
               │  allocs/op  │  allocs/op   vs base          │
LocalCounter-4   121.6k ± 0%   121.6k ± 0%  ~ (p=0.289 n=10)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant