Skip to content

MVP-Improve

Choose a tag to compare

@JaredMijail JaredMijail released this 05 Jul 19:38
· 13 commits to main since this release

🔐 JWT Role Middleware - Refactored Architecture

✨ What's New

  • Improved Architecture: Middleware now uses a configuration object pattern for better separation of concerns
  • Enhanced Security: Secret key and environment mode (devops/production) are configured once at middleware creation
  • Better Performance: Configuration is pre-computed, reducing runtime overhead
  • Cleaner API: Simplified usage with NewJwtRoleMiddleware() and config.Handler()

�� Key Improvements

  • Eliminated Parameter Duplication: No more passing secret and devops flags in every handler call
  • Reduced Error Risk: Configuration validation happens at creation time, not runtime
  • Improved Maintainability: Single configuration object can be reused across multiple routes
  • Better Testing: Cleaner test structure with consolidated test suite

�� Usage

// Create middleware configuration once
authConfig := middleware.NewJwtRoleMiddleware(false, "your-secret")

// Reuse for different routes
app.Use(authConfig.Handler(false, "admin", "user"))
app.Use(authConfig.Handler(true, "admin"))  // pass mode

�� Testing

  • 28 comprehensive tests covering all scenarios
  • Single benchmark with consistent ~29μs performance
  • 95%+ test coverage with edge cases and error handling

�� Breaking Changes

  • Removed deprecated JwtRoleMiddleware() function
  • All code must now use the new configuration-based API

Performance: ~29μs per request | Memory: ~16KB/op | Allocations: 110 allocs/op