2024-09-08 10:09:54 +02:00
|
|
|
package main
|
2024-08-20 08:34:11 +02:00
|
|
|
|
2024-08-22 07:18:50 +02:00
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
)
|
2024-08-16 14:25:06 +02:00
|
|
|
|
|
|
|
type Memory struct {
|
2024-09-09 07:36:05 +02:00
|
|
|
items map[string]Item
|
2024-08-16 14:25:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewMemory() *Memory {
|
|
|
|
return &Memory{
|
2024-09-09 07:36:05 +02:00
|
|
|
items: make(map[string]Item),
|
2024-08-16 14:25:06 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-09-09 07:36:05 +02:00
|
|
|
func (m *Memory) Update(item Item) error {
|
2024-08-28 07:21:02 +02:00
|
|
|
m.items[item.ID] = item
|
2024-08-23 10:52:17 +02:00
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2024-09-09 07:36:05 +02:00
|
|
|
func (m *Memory) Updated(timestamp time.Time) ([]Item, error) {
|
|
|
|
result := make([]Item, 0)
|
2024-08-22 07:18:50 +02:00
|
|
|
|
|
|
|
for _, i := range m.items {
|
2024-08-28 07:21:02 +02:00
|
|
|
if timestamp.IsZero() || i.Updated.Equal(timestamp) || i.Updated.After(timestamp) {
|
2024-08-22 07:18:50 +02:00
|
|
|
result = append(result, i)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result, nil
|
|
|
|
}
|