summaryrefslogtreecommitdiff
path: root/entry.go
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2024-05-05 15:50:06 +0300
committerPaul Buetow <paul@buetow.org>2024-05-05 15:50:06 +0300
commitbc3850054cd182fd84e180482e88935aa3559a1c (patch)
tree4073c0579c4115870109801371b2b5e1a40c68b1 /entry.go
parentf173d052d3f8679716862d233d8751f67d3b197c (diff)
use sha checksum as the id
Diffstat (limited to 'entry.go')
-rw-r--r--entry.go7
1 files changed, 5 insertions, 2 deletions
diff --git a/entry.go b/entry.go
index 1615392..a91e0b7 100644
--- a/entry.go
+++ b/entry.go
@@ -1,6 +1,7 @@
package main
import (
+ "crypto/sha256"
"encoding/json"
"fmt"
)
@@ -14,13 +15,15 @@ type entry struct {
Body string `json:"body"`
Shared []shared `json:"shared,omitempty"`
Epoch int `json:"epoch,omitempty"`
+ id string
}
-func newEntry(data []byte) (entry, error) {
+func newEntry(bytes []byte) (entry, error) {
var entry entry
- if err := json.Unmarshal(data, &entry); err != nil {
+ if err := json.Unmarshal(bytes, &entry); err != nil {
return entry, fmt.Errorf("unable to deserialise payload: %w", err)
}
+ entry.id = fmt.Sprintf("%x", sha256.Sum256(bytes))
return entry, nil
}