mirror of
https://github.com/router-for-me/CLIProxyAPI.git
synced 2026-02-03 04:50:52 +08:00
refactor(access): Introduce ApplyAccessProviders helper function
The logic for reconciling access providers, updating the manager, and logging the changes was previously handled directly in the service layer. This commit introduces a new `ApplyAccessProviders` helper function in the `internal/access` package to encapsulate this entire process. The service layer is updated to use this new helper, which simplifies its implementation and reduces code duplication. This refactoring centralizes the provider update logic and improves overall code maintainability. Additionally, the `sdk/access` package import is now aliased to `sdkaccess` for clarity.
This commit is contained in:
@@ -115,19 +115,9 @@ func (s *Service) refreshAccessProviders(cfg *config.Config) {
|
||||
oldCfg := s.cfg
|
||||
s.cfgMu.RUnlock()
|
||||
|
||||
existing := s.accessManager.Providers()
|
||||
providers, added, updated, removed, err := access.ReconcileProviders(oldCfg, cfg, existing)
|
||||
if err != nil {
|
||||
log.Errorf("failed to reconcile request auth providers: %v", err)
|
||||
if _, err := access.ApplyAccessProviders(s.accessManager, oldCfg, cfg); err != nil {
|
||||
return
|
||||
}
|
||||
s.accessManager.SetProviders(providers)
|
||||
if len(added)+len(updated)+len(removed) > 0 {
|
||||
log.Debugf("auth providers reconciled (added=%d updated=%d removed=%d)", len(added), len(updated), len(removed))
|
||||
log.Debugf("auth provider changes details - added=%v updated=%v removed=%v", added, updated, removed)
|
||||
} else {
|
||||
log.Debug("auth providers unchanged after config reload")
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Service) ensureAuthUpdateQueue(ctx context.Context) {
|
||||
|
||||
Reference in New Issue
Block a user