diff options
| author | Paul Buetow <paul@buetow.org> | 2024-05-16 00:59:39 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2024-05-16 00:59:39 +0300 |
| commit | 5b448c4ecf176983f73bfd5d4e1980f6ac509403 (patch) | |
| tree | 3bc362534acb337629aa8a631906250b179e2e49 /internal/types | |
| parent | dc6f16912693a7a95d7375f08d42600ea2ce130e (diff) | |
more on this
Diffstat (limited to 'internal/types')
| -rw-r--r-- | internal/types/entry.go | 29 |
1 files changed, 20 insertions, 9 deletions
diff --git a/internal/types/entry.go b/internal/types/entry.go index fe0b4f5..90b5e6f 100644 --- a/internal/types/entry.go +++ b/internal/types/entry.go @@ -30,16 +30,22 @@ type Entry struct { } func NewEntry(bytes []byte) (Entry, error) { - var ent Entry - if err := json.Unmarshal(bytes, &ent); err != nil { - return ent, fmt.Errorf("unable to deserialise payload: %w", err) + var e Entry + if err := json.Unmarshal(bytes, &e); err != nil { + return e, fmt.Errorf("unable to deserialise payload: %w", err) } - ent.mu = &sync.Mutex{} - ent.dirty = true - if ent.ID == "" { - ent.ID = fmt.Sprintf("%x", sha256.Sum256(bytes)) + e.initialize() + if e.ID == "" { + e.ID = fmt.Sprintf("%x", sha256.Sum256(bytes)) } - return ent, nil + return e, nil +} + +// Beware , this is only from a shallow copy! +func NewEntryFromCopy(other Entry) Entry { + e := other + e.initialize() + return e } func NewEntryFromFile(filePath string) (Entry, error) { @@ -50,7 +56,12 @@ func NewEntryFromFile(filePath string) (Entry, error) { return NewEntry(bytes) } -func (e Entry) Update(new Entry) Entry { +func (e *Entry) initialize() { + e.mu = &sync.Mutex{} + e.dirty = true +} + +func (e Entry) Updated(other Entry) Entry { panic("not yet implemented") //return e } |
