blob: a91e0b72ceb3ce3cbeaf51b87098951218821e75 (
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
30
31
32
|
package main
import (
"crypto/sha256"
"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"`
id string
}
func newEntry(bytes []byte) (entry, error) {
var entry entry
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
}
func (e entry) serialize() ([]byte, error) {
return json.Marshal(e)
}
|