diff options
author | 2021-09-12 10:10:24 +0100 | |
---|---|---|
committer | 2021-09-12 10:10:24 +0100 | |
commit | f6492d12d948507021bbe934de94e87e20464c01 (patch) | |
tree | 6705d6ef6f3c4d70f3b3ebc77c2960d8e508cf37 /internal/blob/inmem.go | |
parent | Merge pull request #213 from superseriousbusiness/alpine+node_upstep (diff) | |
parent | fix keys used to access storage items (diff) | |
download | gotosocial-f6492d12d948507021bbe934de94e87e20464c01.tar.xz |
Merge pull request #214 from NyaaaWhatsUpDoc/improvement/update-storage-library
add git.iim.gay/grufwub/go-store for storage backend, replacing blob.Storage
Diffstat (limited to 'internal/blob/inmem.go')
-rw-r--r-- | internal/blob/inmem.go | 55 |
1 files changed, 0 insertions, 55 deletions
diff --git a/internal/blob/inmem.go b/internal/blob/inmem.go deleted file mode 100644 index 6ea64bcfe..000000000 --- a/internal/blob/inmem.go +++ /dev/null @@ -1,55 +0,0 @@ -package blob - -import ( - "fmt" - - "github.com/sirupsen/logrus" - "github.com/superseriousbusiness/gotosocial/internal/config" -) - -// NewInMem returns an in-memory implementation of the Storage interface. -// This is good for testing and whatnot but ***SHOULD ABSOLUTELY NOT EVER -// BE USED IN A PRODUCTION SETTING***, because A) everything will be wiped out -// if you restart the server and B) if you store lots of images your RAM use -// will absolutely go through the roof. -func NewInMem(c *config.Config, log *logrus.Logger) (Storage, error) { - return &inMemStorage{ - stored: make(map[string][]byte), - log: log, - }, nil -} - -type inMemStorage struct { - stored map[string][]byte - log *logrus.Logger -} - -func (s *inMemStorage) StoreFileAt(path string, data []byte) error { - l := s.log.WithField("func", "StoreFileAt") - l.Debugf("storing at path %s", path) - s.stored[path] = data - return nil -} - -func (s *inMemStorage) RetrieveFileFrom(path string) ([]byte, error) { - l := s.log.WithField("func", "RetrieveFileFrom") - l.Debugf("retrieving from path %s", path) - d, ok := s.stored[path] - if !ok || len(d) == 0 { - return nil, fmt.Errorf("no data found at path %s", path) - } - return d, nil -} - -func (s *inMemStorage) ListKeys() ([]string, error) { - keys := []string{} - for k := range s.stored { - keys = append(keys, k) - } - return keys, nil -} - -func (s *inMemStorage) RemoveFileAt(path string) error { - delete(s.stored, path) - return nil -} |