~chrisppy/go-barefeed

ref: 022d6ea6f0215c28fa4b4b69dd9d821c8766ded8 go-barefeed/message.go -rw-r--r-- 616 bytes
022d6ea6Chris Palmer updates from barefeed fixes 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
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     Feeds     `bare:"feeds"`
}

// 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)
}