Skip to content

feat(router)!: inherit sub-router overrides; add global auth token#111

Merged
Suhaibinator merged 3 commits into
mainfrom
authConfig
Jun 7, 2026
Merged

feat(router)!: inherit sub-router overrides; add global auth token#111
Suhaibinator merged 3 commits into
mainfrom
authConfig

Conversation

@Suhaibinator

@Suhaibinator Suhaibinator commented Jun 7, 2026

Copy link
Copy Markdown
Owner

Nested sub-routers now inherit their parent sub-router's configuration
overrides (timeout, max body size, rate limit, and auth token source)
by default. Previously these were not inherited and each nested level
had to redeclare them. Set SubRouterConfig.IsolateOverrides to opt a
sub-router (and its descendants) out of parent inheritance; RouterConfig
globals still apply.

Also:

  • Add RouterConfig.GlobalAuthToken for an application-wide default auth
    token source. Effective precedence is now: route override, current or
    inherited sub-router override, global config, then the built-in
    Authorization header default.
  • Log a registration-time warning when an AuthRequired route resolves to
    the built-in default token source because no route, sub-router, or
    global source is configured.
  • Resolve sub-router lookups by full path prefix so dynamic registration
    via RegisterGenericRouteOnSubRouter on a nested sub-router produces the
    correct concatenated path (relative-prefix lookup retained as a
    fallback).
  • Update README and docs for the new precedence and inheritance rules.

BREAKING CHANGE: Sub-router configuration overrides (timeout, max body
size, rate limit, auth token source) are now inherited by nested
sub-routers by default. Routes in nested sub-routers that previously fell
through to RouterConfig globals will now pick up the parent sub-router's
overrides. This can change effective timeouts, rate limits, body-size
limits, and—most importantly—the auth token source used for AuthRequired
routes. Audit nested sub-routers and set IsolateOverrides: true where the
previous (non-inherited) behavior is required.

Update README and authentication docs to cover the new
`RouterConfig.GlobalAuthToken` option for global auth token sources
and the `SubRouterConfig.IsolateOverrides` flag. Clarify that auth
token source precedence follows: route override, sub-router override,
global config, then the default Authorization header.
@codecov

codecov Bot commented Jun 7, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.57%. Comparing base (36bd9f8) to head (1a8099f).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #111      +/-   ##
==========================================
+ Coverage   97.49%   97.57%   +0.08%     
==========================================
  Files          18       18              
  Lines        1873     1935      +62     
==========================================
+ Hits         1826     1888      +62     
  Misses         35       35              
  Partials       12       12              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Suhaibinator Suhaibinator changed the title docs: document GlobalAuthToken, IsolateOverrides, and auth precedence feat(router)!: inherit sub-router overrides; add global auth token Jun 7, 2026
- Update GitHub Actions workflows to use Go 1.26.3
- Expand documentation for authRequiredMiddleware and
  authOptionalMiddleware to clarify default auth token
  config usage and relationship to WithConfig variants
Migrate test assertions from implicit global config middleware helpers
to explicit *WithConfig variants. Update getEffectiveAuthTokenConfig
calls to use the WithOrigin accessor and remove a redundant test case.
@Suhaibinator Suhaibinator merged commit 9858b39 into main Jun 7, 2026
11 checks passed
@Suhaibinator Suhaibinator deleted the authConfig branch June 7, 2026 16:47
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