@@ -57,6 +57,8 @@ func (s *memoryStorage) Exists(ctx context.Context, key string) bool {
5757
5858// Store saves value at key.
5959func (s * memoryStorage ) Store (_ context.Context , key string , value []byte ) error {
60+ s .mu .Lock ()
61+ defer s .mu .Unlock ()
6062 s .m [key ] = storageEntry {
6163 i : KeyInfo {
6264 Key : key ,
@@ -71,6 +73,8 @@ func (s *memoryStorage) Store(_ context.Context, key string, value []byte) error
7173
7274// Load retrieves the value at key.
7375func (s * memoryStorage ) Load (_ context.Context , key string ) ([]byte , error ) {
76+ s .mu .Lock ()
77+ defer s .mu .Unlock ()
7478 val , ok := s .m [key ]
7579 if ! ok {
7680 return nil , os .ErrNotExist
@@ -80,12 +84,20 @@ func (s *memoryStorage) Load(_ context.Context, key string) ([]byte, error) {
8084
8185// Delete deletes the value at key.
8286func (s * memoryStorage ) Delete (_ context.Context , key string ) error {
87+ s .mu .Lock ()
88+ defer s .mu .Unlock ()
8389 delete (s .m , key )
8490 return nil
8591}
8692
8793// List returns all keys that match prefix.
8894func (s * memoryStorage ) List (ctx context.Context , prefix string , recursive bool ) ([]string , error ) {
95+ s .mu .Lock ()
96+ defer s .mu .Unlock ()
97+ return s .list (ctx , prefix , recursive )
98+ }
99+
100+ func (s * memoryStorage ) list (ctx context.Context , prefix string , recursive bool ) ([]string , error ) {
89101 var keyList []string
90102
91103 keys := make ([]string , 0 , len (s .m ))
@@ -104,7 +116,7 @@ func (s *memoryStorage) List(ctx context.Context, prefix string, recursive bool)
104116 // If current key is a directory
105117 if recursive && k != trimmedKey {
106118 // Recursively traverse all child directories
107- childKeys , err := s .List (ctx , fullPathKey , recursive )
119+ childKeys , err := s .list (ctx , fullPathKey , recursive )
108120 if err != nil {
109121 return keyList , err
110122 }
@@ -119,6 +131,8 @@ func (s *memoryStorage) List(ctx context.Context, prefix string, recursive bool)
119131
120132// Stat returns information about key.
121133func (s * memoryStorage ) Stat (_ context.Context , key string ) (KeyInfo , error ) {
134+ s .mu .Lock ()
135+ defer s .mu .Unlock ()
122136 val , ok := s .m [key ]
123137 if ! ok {
124138 return KeyInfo {}, os .ErrNotExist
0 commit comments