forked from mtusi2026/mtusi2026lab3
26 lines
620 B
Go
26 lines
620 B
Go
package memory
|
|
|
|
import (
|
|
"bytes"
|
|
"time"
|
|
|
|
"github.com/google/uuid"
|
|
|
|
"gitea.privcloud.tech/vlad_marlo/mtusi2026lab3/internal/model/dto"
|
|
)
|
|
|
|
// timestamp is called under the write lock, keeping append order during clock rollback.
|
|
func (s *Store) timestamp() time.Time {
|
|
now := time.Now().UTC()
|
|
if !now.After(s.lastTime) {
|
|
now = s.lastTime.Add(time.Nanosecond)
|
|
}
|
|
s.lastTime = now
|
|
return now
|
|
}
|
|
|
|
// after compares a record with a keyset pagination position.
|
|
func after(t time.Time, id uuid.UUID, p dto.PositionDTO) bool {
|
|
return t.After(p.CreatedAt) || (t.Equal(p.CreatedAt) && bytes.Compare(id[:], p.ID[:]) > 0)
|
|
}
|