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-commenter commented Nov 21, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (v3-dev@3dda627). Learn more about missing BASE report.

Additional details and impacted files
@@            Coverage Diff            @@
##             v3-dev     #356   +/-   ##
=========================================
  Coverage          ?   97.72%           
=========================================
  Files             ?       13           
  Lines             ?      396           
  Branches          ?        0           
=========================================
  Hits              ?      387           
  Misses            ?        6           
  Partials          ?        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
Base automatically changed from v3-phase1-pr1-project-setup to v3-dev November 27, 2025 05:36
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