slask
Some checks failed
Build and Publish / BuildAndDeploy (push) Failing after 8s

This commit is contained in:
matst80
2025-05-15 19:28:34 +02:00
commit 19b7299966
8 changed files with 513 additions and 0 deletions

View File

@@ -0,0 +1,44 @@
package storage
import (
"bytes"
"io"
"os"
)
type MemoryStorage struct {
cache map[string][]byte
}
func NewMemoryStorage(ids []string) (Storage, error) {
s := &MemoryStorage{
cache: make(map[string][]byte),
}
return s, nil
}
func (ms *MemoryStorage) Get(key string) (io.Reader, error) {
content, ok := ms.cache[key]
if !ok {
return nil, os.ErrNotExist
}
return bytes.NewReader(content), nil
}
func (ms *MemoryStorage) Put(key string, data []byte) error {
ms.cache[key] = data
return nil
}
func (ms *MemoryStorage) Delete(key string) error {
delete(ms.cache, key)
return nil
}
func (ms *MemoryStorage) List(prefix string) ([]string, error) {
res := make([]string, 0, len(ms.cache))
for file, _ := range ms.cache {
res = append(res, file)
}
return res, nil
}