mirror of
https://github.com/superseriousbusiness/gotosocial
synced 2025-06-05 21:59:39 +02:00
Move a lot of stuff + tidy stuff (#37)
Lots of renaming and moving stuff, some bug fixes, more lenient parsing of notifications and home timeline.
This commit is contained in:
55
internal/blob/inmem.go
Normal file
55
internal/blob/inmem.go
Normal file
@ -0,0 +1,55 @@
|
||||
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
|
||||
}
|
Reference in New Issue
Block a user