Skip to content

Conversation

@developerkunal
Copy link
Contributor

📝 Checklist

  • All new/changed/fixed functionality is covered by tests (or N/A)
  • I have added documentation for all new/changed functionality (or N/A)

🔧 Changes

This PR introduces a framework-agnostic validation engine that separates validation logic from transport-specific concerns, enabling support for multiple frameworks (HTTP, gRPC, Gin, Echo, etc.).

New Package: core/

Types Added:

  • Core - Framework-agnostic validation engine
  • TokenValidator interface - Interface for JWT validation
  • Logger interface - Optional logging interface
  • ValidationError - Structured error type with error codes
  • Option - Error-returning option functions

Functions Added:

  • New(opts ...Option) (*Core, error) - Constructor with options pattern
  • CheckToken(ctx, token) (any, error) - Pure validation logic
  • GetClaims[T](ctx) (T, error) - Type-safe generic claims retrieval
  • SetClaims(ctx, claims) context.Context - Helper to store claims
  • HasClaims(ctx) bool - Check if claims exist
  • WithValidator(TokenValidator) Option - Required option
  • WithCredentialsOptional(bool) Option - Configure optional credentials
  • WithLogger(Logger) Option - Configure logging

Key Features:

  • Framework-agnostic: No HTTP/gRPC dependencies
  • Type-safe generics for claims retrieval
  • Structured errors with error codes
  • 100% test coverage
  • Secure defaults

📚 References

  • Depends on PR 1.1 (Project Setup)

🔬 Testing

Test Coverage:

go test -v -coverprofile=coverage.out ./core/...
# Result: 100.0% coverage

Tests Include:

  • Constructor validation
  • Token validation scenarios
  • Credentials optional logic
  • Logger integration
  • Context propagation
  • Type-safe context helpers
  • Error handling

Run Tests:

go test -v ./core/...
go test -race ./core/...

All tests pass with 100% coverage.

   This implements the Core-Adapter Architecture for v3, separating
   framework-agnostic validation logic from transport-specific adapters.

   Key Features:
   - Core struct with CheckToken method for pure validation logic
   - Options pattern with error-returning option functions
   - Type-safe context helpers using generics (GetClaims[T])
   - Unexported contextKey int to prevent collisions (Go best practice)
   - Structured error types with error codes
   - Logger interface for observability
   - 100% test coverage

   Changes:
   - Add core/core.go: Framework-agnostic validation engine
   - Add core/option.go: Options pattern with validation
   - Add core/errors.go: Structured errors and error codes
   - Add core/context.go: Type-safe context helpers
   - Add core/core_test.go: Comprehensive tests

   This enables future support for multiple frameworks (HTTP, gRPC, Gin,
   Echo, etc.) by wrapping the Core with transport-specific adapters.

   Part of PR 1.2 in v3 Phase 1 implementation.
@developerkunal developerkunal requested a review from a team as a code owner November 21, 2025 09:06
@codecov-commenter
Copy link

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.72%. Comparing base (fed2e86) to head (ce89f57).

Additional details and impacted files
@@                       Coverage Diff                       @@
##           v3-phase1-pr1-project-setup     #356      +/-   ##
===============================================================
+ Coverage                        97.13%   97.72%   +0.59%     
===============================================================
  Files                                9       13       +4     
  Lines                              314      396      +82     
===============================================================
+ Hits                               305      387      +82     
  Misses                               6        6              
  Partials                             3        3              

☔ View full report in Codecov by Sentry.
📢 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.

@developerkunal developerkunal changed the title PR 1.2: Add framework-agnostic core package for v3 chore: PR 1.2 Add framework-agnostic core package for v3 Nov 21, 2025
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.

3 participants