Skip to content

📒 doc: fix keyauth extractor examples#4409

Merged
gaby merged 2 commits into
gofiber:mainfrom
DucMinhNe:docs/keyauth-extractors-fromcookie
Jun 7, 2026
Merged

📒 doc: fix keyauth extractor examples#4409
gaby merged 2 commits into
gofiber:mainfrom
DucMinhNe:docs/keyauth-extractors-fromcookie

Conversation

@DucMinhNe

Copy link
Copy Markdown
Contributor

Description

The KeyAuth middleware docs (docs/middleware/keyauth.md) have three runnable package main examples, and all three fail to compile as written:

  1. Basic example and Authenticate only certain endpoints call keyauth.FromCookie("access_token") — but FromCookie does not exist in the keyauth package. go vet reports undefined: keyauth.FromCookie.
  2. Apply middleware in the handler is fine, but the Typical Usage snippet and the rest of the page correctly use extractors.FromCookie(...) from the shared github.com/gofiber/fiber/v3/extractors package — and the first two examples never import that package.

In Fiber v3 the extractor helpers live in the shared extractors package (the keyauth package itself imports it and defaults to extractors.FromAuthHeader). The page's own Config table already says to use extractors.FromCookie(...) from "the shared extractors package", so the early examples were just internally inconsistent.

Fix

  • Add the missing "github.com/gofiber/fiber/v3/extractors" import to the example import blocks.
  • Replace keyauth.FromCookie(...) with extractors.FromCookie(...) in the two affected examples.

After the change all three examples compile (go vet passes; the originals failed). Docs-only.

@coderabbitai

coderabbitai Bot commented Jun 7, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

Documentation examples for KeyAuth cookie-based extraction were updated to import github.com/gofiber/fiber/v3/extractors and use Extractor: extractors.FromCookie("access_token") in the affected example blocks.

Changes

KeyAuth Documentation Examples

Layer / File(s) Summary
KeyAuth examples using shared extractors
docs/middleware/keyauth.md
Two KeyAuth middleware example blocks updated to import github.com/gofiber/fiber/v3/extractors and replace keyauth.FromCookie("access_token") with extractors.FromCookie("access_token").

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Possibly related PRs

  • gofiber/fiber#3707: KeyAuth extractor-pattern API/doc migration work related to switching examples to extractors.FromCookie(...).
  • gofiber/fiber#3685: Introduction/refactor around the shared extractors package used by these examples.
  • gofiber/fiber#3742: RFC/compliance changes aligning KeyAuth with extractor-based configuration.

Suggested reviewers

  • sixcolors
  • efectn
  • ReneWerner87

Poem

🐰 I hopped through docs to make things neat,

extractors now handle the cookie treat,
examples trimmed, imports set right,
readers bounce with clearer light,
munching carrots, I take flight.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description check ✅ Passed The PR description clearly explains the problem (non-compiling examples), identifies the root cause (missing import and incorrect function reference), and details the fix applied, aligning with the template's documentation update focus.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title references the main change (fixing KeyAuth extractor examples), though it uses an emoji and is somewhat abbreviated compared to the detailed PR objectives.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@ReneWerner87 ReneWerner87 added this to v3 Jun 7, 2026
@ReneWerner87 ReneWerner87 added this to the v3 milestone Jun 7, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@docs/middleware/keyauth.md`:
- Line 184: The example under "Apply middleware in the handler" imports the
unused symbol `extractors` from "github.com/gofiber/fiber/v3/extractors"; remove
that import entry so the Go snippet no longer includes `extractors` and remains
lint-clean, leaving the other imports and the example code unchanged.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: b883bbeb-2545-47b0-b630-75528b54d2a3

📥 Commits

Reviewing files that changed from the base of the PR and between 60e53a3 and ea3853a.

📒 Files selected for processing (1)
  • docs/middleware/keyauth.md

Comment thread docs/middleware/keyauth.md Outdated

@sixcolors sixcolors left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bot comment about default not requiring import is correct otherwise LGTM

@DucMinhNe

Copy link
Copy Markdown
Contributor Author

Good catch — thanks @sixcolors / CodeRabbit. The third example ("Apply middleware in the handler") uses the default extractor and doesn't reference extractors, so the import was unused. Removed it; the other two examples keep the import since they call extractors.FromCookie. 🙏

@gaby gaby changed the title 📚 Doc: fix non-compiling keyauth extractor examples (extractors.FromCookie + import) 📒 doc: fix keyauth extractor examples Jun 7, 2026
@gaby gaby merged commit 5c45bce into gofiber:main Jun 7, 2026
7 checks passed
@welcome

welcome Bot commented Jun 7, 2026

Copy link
Copy Markdown

Congrats on merging your first pull request! 🎉 We here at Fiber are proud of you! If you need help or want to chat with us, join us on Discord https://gofiber.io/discord

@github-project-automation github-project-automation Bot moved this to Done in v3 Jun 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants