Skip to content

Update Go version requirement to 1.26.0 and refactor auth/context APIs#112

Merged
Suhaibinator merged 1 commit into
mainfrom
claude/great-hopper-ZWMes
Jun 8, 2026
Merged

Update Go version requirement to 1.26.0 and refactor auth/context APIs#112
Suhaibinator merged 1 commit into
mainfrom
claude/great-hopper-ZWMes

Conversation

@Suhaibinator

Copy link
Copy Markdown
Owner

Summary

This PR updates the minimum Go version requirement from 1.24.0 to 1.26.0 and introduces significant API changes to authentication and context handling. The authentication function now returns a pointer to the user object instead of the object itself, improving memory efficiency and consistency with the context management system. Documentation has been comprehensively updated to reflect these changes and clarify several implementation details.

Key Changes

Authentication API Refactoring

  • Auth function signature change: authFunction now returns (*UserObjectType, bool) instead of (UserObjectType, bool)
    • This aligns with how user objects are stored in SRouterContext (as pointers)
    • Reduces memory overhead for large user objects
    • Updated all documentation examples and getting-started guide accordingly

Context Management Improvements

  • Flags map type change: SRouterContext.Flags now stores map[string]bool instead of map[string]any
    • Clarifies that flags are boolean indicators (e.g., set by AuthenticationBool middleware)
    • Arbitrary values should use standard context.WithValue() API
    • Updated middleware examples to demonstrate proper usage patterns

Documentation Clarifications

  • Metrics system: Clarified that MiddlewareFactory is reserved but not currently consumed; SRouter always builds its own metrics middleware from Collector
  • IP source configuration: Added detailed explanation of IP extraction behavior with fallback logic
  • Middleware execution order: Expanded documentation with 9-step execution flow including recovery, trace ID, auth, rate limiting, route/sub-router middleware, global middleware, timeout, base handler, and user handler
  • CORS handling: Clarified that CORS is handled directly by the router via RouterConfig.CORSConfig, not as standalone middleware
  • Codec interface location: Corrected documentation to reference pkg/codec/codec.go instead of pkg/router/config.go
  • Trace middleware signature: Updated to include generic type parameters [T comparable, U any]
  • Custom middleware examples: Improved RequestIDMiddleware example showing proper use of standard context API for non-boolean values

Configuration Updates

  • RouteConfigBase: Added DisableTimeout field documentation for long-lived connections (WebSockets, etc.)
  • SourceType enum: Added Empty source type that acts as a no-op for decoding
  • AuthLevel documentation: Clarified that pointer syntax new(router.AuthRequired) is the standard way to set auth levels

Minor Fixes

  • Fixed import statement in example code (changed from pkg/middleware to pkg/scontext)
  • Corrected generic type parameter count documentation (4 instead of 5 for RegisterGenericRoute)
  • Updated metrics collection descriptions with specific metric names and tagging schemes
  • Improved BasicUserAuthProvider documentation with direct construction pattern

Implementation Details

  • All changes are backward-incompatible for authentication function signatures and context flag usage
  • The pointer-based auth return value is more consistent with Go idioms for optional values
  • Documentation updates provide clear migration guidance for existing code
  • Examples throughout the codebase have been updated to demonstrate the new patterns

https://claude.ai/code/session_01X4xFQGLsqaGriQuH121Kv9

Audit docs/README against the code and fix drift accumulated since recent
features (Overrides/RouteOverrides, GlobalAuthToken, WebSocket DisableTimeout,
ProtoCodec changes, removal of CORS middleware, new(expr) usage).

- Bump documented Go version to 1.26.0 (matches go.mod) across
  README, getting-started, AGENTS.md, CLAUDE.md
- Fix NewRouter auth function signatures to use pointer user object
  (*U) in README quick-start and getting-started example
- Correct middleware execution order (Recovery outermost, Trace,
  Auth, RateLimit, route/sub-router, global, Timeout, base handler)
- Document DisableTimeout on RouteConfigBase and add the websocket example
- Replace removed/non-existent API references: CORS middleware -> CORSConfig,
  NewBasicUserAuthProvider -> BasicUserAuthProvider literal, add
  CreateTraceMiddleware type params, drop the obsolete AuthLevel Ptr helper
- Correct metrics docs: latency Histogram tagged by route, throughput is a
  request-body-bytes Counter, QPS/errors tags; note MiddlewareFactory is
  not currently consumed by the router
- Fix Flags type (map[string]bool), WithUser/WithFlag usage, scontext import,
  RouteConfig Sanitizer field, Empty SourceType, ExceededHandler type,
  MaxBodySize (was MaxBodyBytes), CORSConfig MaxAge type, context-management
  httprouter import

https://claude.ai/code/session_01X4xFQGLsqaGriQuH121Kv9
@Suhaibinator Suhaibinator merged commit 6681e73 into main Jun 8, 2026
9 checks passed
@codecov

codecov Bot commented Jun 8, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.57%. Comparing base (9858b39) to head (122d910).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #112   +/-   ##
=======================================
  Coverage   97.57%   97.57%           
=======================================
  Files          18       18           
  Lines        1935     1935           
=======================================
  Hits         1888     1888           
  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.

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.

2 participants