Skip to content
Snippets Groups Projects
Commit 570a8c91 authored by gjahn's avatar gjahn
Browse files

Store actual items in ephemeral storage instead of pointers

The location where the actual items should reside is in the store, while
only references are being returned when attempting to access an item.
parent 197ca0ea
No related branches found
No related tags found
No related merge requests found
...@@ -20,7 +20,7 @@ func NewEphemeralStore() *Ephemeral { ...@@ -20,7 +20,7 @@ func NewEphemeralStore() *Ephemeral {
} }
func ( e *Ephemeral ) Add( i *Item ) error { func ( e *Ephemeral ) Add( i Item ) error {
if e.store == nil { if e.store == nil {
return errors.New( "ephemeral storage not available" ) return errors.New( "ephemeral storage not available" )
} }
...@@ -60,7 +60,7 @@ func ( e *Ephemeral ) Fetch( name string ) ( *Item, error ) { ...@@ -60,7 +60,7 @@ func ( e *Ephemeral ) Fetch( name string ) ( *Item, error ) {
if !found { if !found {
return nil, nil return nil, nil
} }
return item, nil return &item, nil
} }
......
...@@ -8,8 +8,8 @@ type Item struct { ...@@ -8,8 +8,8 @@ type Item struct {
} }
func NewItem( name string, mimeType string, data []byte ) *Item { func NewItem( name string, mimeType string, data []byte ) Item {
return &Item{ return Item{
name: name, name: name,
mimeType: mimeType, mimeType: mimeType,
data: data, data: data,
......
...@@ -44,7 +44,7 @@ func NewPersistentStore( c *configuration.Config ) *Persistent { ...@@ -44,7 +44,7 @@ func NewPersistentStore( c *configuration.Config ) *Persistent {
} }
func ( e *Persistent ) Add( i *Item ) error { func ( e *Persistent ) Add( i Item ) error {
ctx, cancel := context.WithTimeout( context.TODO(), e.timeout ) ctx, cancel := context.WithTimeout( context.TODO(), e.timeout )
defer cancel() defer cancel()
...@@ -82,7 +82,8 @@ func ( e *Persistent ) Fetch( name string ) ( *Item, error ) { ...@@ -82,7 +82,8 @@ func ( e *Persistent ) Fetch( name string ) ( *Item, error ) {
var item *Item = nil var item *Item = nil
if len( value ) >= 1 { if len( value ) >= 1 {
item = NewItem( name, value[ "mime" ], []byte( value[ "data" ] ) ) i := NewItem( name, value[ "mime" ], []byte( value[ "data" ] ) )
item = &i
} }
return item, nil return item, nil
} }
......
...@@ -3,7 +3,7 @@ package state ...@@ -3,7 +3,7 @@ package state
type Store interface { type Store interface {
Add( i *Item ) error Add( i Item ) error
Remove( name string ) error Remove( name string ) error
Fetch( name string ) ( *Item, error ) Fetch( name string ) ( *Item, error )
Show() ( []string, error ) Show() ( []string, error )
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment