mirror of
https://github.com/router-for-me/CLIProxyAPIPlus.git
synced 2026-03-21 16:40:22 +00:00
feat(proxy): centralize proxy handling with `proxyutil` package and enhance test coverage - Added `proxyutil` package to simplify proxy handling across the codebase. - Refactored various components (`executor`, `cliproxy`, `auth`, etc.) to use `proxyutil` for consistent and reusable proxy logic. - Introduced support for "direct" proxy mode to explicitly bypass all proxies. - Updated tests to validate proxy behavior (e.g., `direct`, HTTP/HTTPS, and SOCKS5). - Enhanced YAML configuration documentation for proxy options.
50 lines
918 B
Go
50 lines
918 B
Go
package management
|
|
|
|
import (
|
|
"context"
|
|
"sync"
|
|
|
|
coreauth "github.com/router-for-me/CLIProxyAPI/v6/sdk/cliproxy/auth"
|
|
)
|
|
|
|
type memoryAuthStore struct {
|
|
mu sync.Mutex
|
|
items map[string]*coreauth.Auth
|
|
}
|
|
|
|
func (s *memoryAuthStore) List(_ context.Context) ([]*coreauth.Auth, error) {
|
|
s.mu.Lock()
|
|
defer s.mu.Unlock()
|
|
|
|
out := make([]*coreauth.Auth, 0, len(s.items))
|
|
for _, item := range s.items {
|
|
out = append(out, item)
|
|
}
|
|
return out, nil
|
|
}
|
|
|
|
func (s *memoryAuthStore) Save(_ context.Context, auth *coreauth.Auth) (string, error) {
|
|
if auth == nil {
|
|
return "", nil
|
|
}
|
|
|
|
s.mu.Lock()
|
|
defer s.mu.Unlock()
|
|
|
|
if s.items == nil {
|
|
s.items = make(map[string]*coreauth.Auth)
|
|
}
|
|
s.items[auth.ID] = auth
|
|
return auth.ID, nil
|
|
}
|
|
|
|
func (s *memoryAuthStore) Delete(_ context.Context, id string) error {
|
|
s.mu.Lock()
|
|
defer s.mu.Unlock()
|
|
|
|
delete(s.items, id)
|
|
return nil
|
|
}
|
|
|
|
func (s *memoryAuthStore) SetBaseDir(string) {}
|