diff options
| author | Paul Buetow <paul@buetow.org> | 2024-05-05 15:43:29 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2024-05-05 15:43:29 +0300 |
| commit | f173d052d3f8679716862d233d8751f67d3b197c (patch) | |
| tree | bfb1e7ca88b669cac319c78aa5c2ebbd737818f1 /entry.go | |
| parent | 2e1e698f3232d72f441bbac7d4bc2c2b29accaf8 (diff) | |
can retrieve JSON payload
Diffstat (limited to 'entry.go')
| -rw-r--r-- | entry.go | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/entry.go b/entry.go new file mode 100644 index 0000000..1615392 --- /dev/null +++ b/entry.go @@ -0,0 +1,29 @@ +package main + +import ( + "encoding/json" + "fmt" +) + +type shared struct { + Name string `json:"id"` + Is bool `json:"is,omitempty"` +} + +type entry struct { + Body string `json:"body"` + Shared []shared `json:"shared,omitempty"` + Epoch int `json:"epoch,omitempty"` +} + +func newEntry(data []byte) (entry, error) { + var entry entry + if err := json.Unmarshal(data, &entry); err != nil { + return entry, fmt.Errorf("unable to deserialise payload: %w", err) + } + return entry, nil +} + +func (e entry) serialize() ([]byte, error) { + return json.Marshal(e) +} |
