summaryrefslogtreecommitdiff
path: root/internal/storage/inmem.go
diff options
context:
space:
mode:
authorLibravatar Tobi Smethurst <31960611+tsmethurst@users.noreply.github.com>2021-04-19 19:42:19 +0200
committerLibravatar GitHub <noreply@github.com>2021-04-19 19:42:19 +0200
commit32c5fd987a06e11b14a4247d13187657c14adedd (patch)
treef5b787ca0f020bea5fd020925e52d3592a77a6ad /internal/storage/inmem.go
parentApi/v1/accounts (#8) (diff)
downloadgotosocial-32c5fd987a06e11b14a4247d13187657c14adedd.tar.xz
Api/v1/statuses (#11)
This PR adds: Statuses New status creation. View existing status Delete a status Fave a status Unfave a status See who's faved a status Media Upload media attachment and store/retrieve it Upload custom emoji and store/retrieve it Fileserver Serve files from storage Testing Test models, testrig -- run a GTS test instance and play around with it.
Diffstat (limited to 'internal/storage/inmem.go')
-rw-r--r--internal/storage/inmem.go24
1 files changed, 24 insertions, 0 deletions
diff --git a/internal/storage/inmem.go b/internal/storage/inmem.go
index 25432fbaa..2d88189db 100644
--- a/internal/storage/inmem.go
+++ b/internal/storage/inmem.go
@@ -7,25 +7,49 @@ import (
"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 {
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
+}