feat: optimize facades.Auth().Guard() return value#967
Conversation
There was a problem hiding this comment.
⚠️ Performance Alert ⚠️
Possible performance regression was detected for benchmark.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 1.50.
| Benchmark suite | Current: ef9e859 | Previous: aec2bbb | Ratio |
|---|---|---|---|
BenchmarkFile_ReadWrite |
346532 ns/op 2073 B/op 28 allocs/op |
228545 ns/op 2072 B/op 28 allocs/op |
1.52 |
BenchmarkFile_ReadWrite - ns/op |
346532 ns/op |
228545 ns/op |
1.52 |
This comment was automatically generated by workflow using github-action-benchmark.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #967 +/- ##
==========================================
+ Coverage 69.15% 69.25% +0.10%
==========================================
Files 160 160
Lines 10718 10712 -6
==========================================
+ Hits 7412 7419 +7
+ Misses 2970 2958 -12
+ Partials 336 335 -1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
| guardFuncs = sync.Map{} | ||
| providersFuncs = sync.Map{} |
There was a problem hiding this comment.
In the previous version, custom guards and custom user providers were missed due to facades.Auth() not being a singleton. Hence, we need to save them to global variables. cc @vendion
| auth.Extend("jwt", NewJwtGuard) | ||
| auth.Provider("orm", NewOrmUserProvider) |
There was a problem hiding this comment.
In the previous version, NewJwtGuard and NewOrmUserProvider do not implement GuardFunc and UserProviderFunc, but they should. cc @vendion
There was a problem hiding this comment.
I checked the session guard driver and the current test cases, there are many test cases that can't be used in the session guard driver, so move them to the jwt_guard_test.go.
a0961c8 to
ef9e859
Compare
📑 Description
This pull request includes significant changes to the
authpackage, focusing on refactoring the authentication system and improving the JWT guard implementation. The most important changes include restructuring theAuthandJwtGuardclasses, updating theOrmUserProvider, and adding new tests for theOrmUserProvider.Refactoring and Improvements to
AuthandJwtGuard:auth/auth.go: Refactored theAuthclass to usesync.Mapfor storing guard and provider functions, removed unused dependencies, and simplified the constructor by eliminating the need forcacheandormparameters. Addedlogas a new dependency.auth/jwt_guard.go: Introduced a newNewJwtGuardfunction to initializeJwtGuardwith context and configuration. Added new fields forsecret,ttl, andrefreshTtltoJwtGuard. Updated methods to use these fields and replaced the oldauthTokenmethod withjwtToken. [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11]Updates to
OrmUserProvider:auth/orm_user_provider.go: RefactoredOrmUserProviderto use the globalormFacadeand added a context parameter to its methods. Implemented error handling for missing ORM facade.auth/orm_user_provider_test.go: Added new test cases forOrmUserProviderto ensure proper functionality and error handling.Dependency Management:
auth/service_provider.go: Updated the service provider to set global facades forcache,config, andorm. Simplified theRegistermethod to handle optional context parameters.Contract Changes:
contracts/auth/auth.go: Updated theAuthandGuardDriverinterfaces to include new methods and error handling. Modified function signatures to accept context parameters.contracts/foundation/application.go: Modified theMakeAuthmethod to accept variadic context parameters.✅ Checks