package storage import ( "bytes" "context" "fmt" "io" "sync" ) // MemoryStorage 测试用内存存储 type MemoryStorage struct { mu sync.RWMutex data map[string][]byte base string } func NewMemory(publicBase string) *MemoryStorage { return &MemoryStorage{ data: make(map[string][]byte), base: NormalizePublicBase(publicBase), } } func (m *MemoryStorage) Put(_ context.Context, key string, r io.Reader, _ int64, _ string) (string, error) { b, err := io.ReadAll(r) if err != nil { return "", err } m.mu.Lock() m.data[key] = b m.mu.Unlock() return m.base + "/" + key, nil } func (m *MemoryStorage) Delete(_ context.Context, key string) error { m.mu.Lock() delete(m.data, key) m.mu.Unlock() return nil } func (m *MemoryStorage) PublicBase() string { return m.base } func (m *MemoryStorage) EnsureBucket(context.Context) error { return nil } func (m *MemoryStorage) HealthCheck(context.Context) error { return nil } func (m *MemoryStorage) Get(key string) ([]byte, error) { m.mu.RLock() defer m.mu.RUnlock() b, ok := m.data[key] if !ok { return nil, fmt.Errorf("not found") } return bytes.Clone(b), nil }