e50cabac4b
- Updated all references from v6 to v7 for `github.com/router-for-me/CLIProxyAPI`. - Ensured consistency in imports within core libraries, tests, and integration tests. - Added missing tests for new features in Redis Protocol integration.
50 lines
918 B
Go
50 lines
918 B
Go
package management
|
|
|
|
import (
|
|
"context"
|
|
"sync"
|
|
|
|
coreauth "github.com/router-for-me/CLIProxyAPI/v7/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) {}
|