summaryrefslogtreecommitdiff
path: root/entry.go
blob: 1615392b0ef0cb70b4b4de02797fe658971fb08a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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)
}