~chrisppy/go-barefeed

ref: e76763008dc2b1750154fb00285056605c882e40 go-barefeed/message.go -rw-r--r-- 796 bytes
e7676300Chris Palmer fix textType 4 months ago
                                                                                
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
33
package barefeed

import (
	"os"
	"path/filepath"

	"git.sr.ht/~sircmpwn/go-bare"
)

// Message is the first version of the spec
type Message struct {
	Generator string               `bare:"generator"`
	Created   Timestamp            `bare:"created"`
	Feeds     map[string]Feed      `bare:"feeds"`
	Entries   map[string]Entry     `bare:"entries"`
	Unread    map[string]int64     `bare:"unread"`
	Favorite  map[string]Timestamp `bare:"favorite"`
}

// Bytes will return the barefeed as a slice of bytes
func (t Message) Bytes() ([]byte, error) {
	return bare.Marshal(&t)
}

// WriteFile will write barefeed to a file at the designated path
func (t Message) WriteFile(path string) error {
	b, err := t.Bytes()
	if err != nil {
		return err
	}

	return os.WriteFile(filepath.Clean(path), b, 0600)
}