36 lines
943 B
Go
36 lines
943 B
Go
|
package storage
|
||
|
|
||
|
// MemoryStorage is a memory task store
|
||
|
type MemoryStorage struct {
|
||
|
taskAttributes []*TaskAttribute
|
||
|
}
|
||
|
|
||
|
// NewMemoryStorage returns an instance of MemoryStorage.
|
||
|
func NewMemoryStorage() *MemoryStorage {
|
||
|
return &MemoryStorage{}
|
||
|
}
|
||
|
|
||
|
// Add adds a task to the memory store.
|
||
|
func (s *MemoryStorage) Add(taskAttribute *TaskAttribute) error {
|
||
|
s.taskAttributes = append(s.taskAttributes, taskAttribute)
|
||
|
return nil
|
||
|
}
|
||
|
|
||
|
// Fetch will return all tasks stored.
|
||
|
func (s *MemoryStorage) Fetch() ([]*TaskAttribute, error) {
|
||
|
return s.taskAttributes, nil
|
||
|
}
|
||
|
|
||
|
// Remove will remove task from store
|
||
|
func (s *MemoryStorage) Remove(taskAttribute *TaskAttribute) error {
|
||
|
var newTaskAttributes []*TaskAttribute
|
||
|
for _, eTaskAttribute := range s.taskAttributes {
|
||
|
if taskAttribute.Hash == eTaskAttribute.Hash {
|
||
|
continue
|
||
|
}
|
||
|
newTaskAttributes = append(newTaskAttributes, eTaskAttribute)
|
||
|
}
|
||
|
s.taskAttributes = newTaskAttributes
|
||
|
return nil
|
||
|
}
|