M barefeed.go => barefeed.go +12 -0
@@ 12,6 12,18 @@ import (
"git.sr.ht/~sircmpwn/go-bare"
)
+// Message it the root type of a barefeed. It allows for future versions of the
+// spec and allowing backward compatability
+type Message interface {
+ bare.Union
+}
+
+func init() {
+ bare.RegisterUnion((*Message)(nil)).
+ Member(*new(MessageV1), 0)
+
+}
+
// FromFile will read barefeed from a file
func FromFile(path string) (*Message, error) {
b, err := ioutil.ReadFile(filepath.Clean(path))
M barefeed_test.go => barefeed_test.go +5 -5
@@ 63,14 63,14 @@ func TestTimestamp(t *testing.T) {
}
func getTestMessage() Message {
- media := Media{
+ media := MediaV1{
Length: int64(2),
Position: int64(1),
Location: "d",
Mimetype: "e",
}
- i := Item{
+ i := ItemV1{
Link: "a",
Title: "b",
Content: "c",
@@ 80,17 80,17 @@ func getTestMessage() Message {
Media: &media,
}
- f := Feed{
+ f := FeedV1{
Feed: "https://example.com/feed.xml",
Title: "Test file",
Description: "This is a test",
Link: "example.com",
- Items: []Item{i},
+ Items: []ItemV1{i},
}
return Message(MessageV1{
Created: ToTimestamp(time.Now()),
Generator: "generated",
- Feeds: []Feed{f},
+ Feeds: []FeedV1{f},
})
}
R msg.go => version1.go +15 -27
@@ 21,7 21,7 @@ func (t *Timestamp) Encode() ([]byte, error) {
type MessageV1 struct {
Created Timestamp `bare:"created"`
Generator string `bare:"generator"`
- Feeds []Feed `bare:"feeds"`
+ Feeds []FeedV1 `bare:"feeds"`
}
// Decode will convert bytes into MessageV1
@@ 34,49 34,49 @@ func (t *MessageV1) Encode() ([]byte, error) {
return bare.Marshal(t)
}
-// Feed type contains elements from RSS Channel & Atom Feed
-type Feed struct {
+// FeedV1 type contains elements from RSS Channel & Atom Feed
+type FeedV1 struct {
Feed string `bare:"feed"`
Title string `bare:"title"`
Description string `bare:"description"`
Link string `bare:"link"`
Updated *Timestamp `bare:"updated"`
- Items []Item `bare:"items"`
+ Items []ItemV1 `bare:"items"`
}
// Decode will convert bytes into Feed
-func (t *Feed) Decode(data []byte) error {
+func (t *FeedV1) Decode(data []byte) error {
return bare.Unmarshal(data, t)
}
// Encode will convert Feed into bytes
-func (t *Feed) Encode() ([]byte, error) {
+func (t *FeedV1) Encode() ([]byte, error) {
return bare.Marshal(t)
}
-// Item type contains elements from RSS Item & Atom Entry
-type Item struct {
+// ItemV1 type contains elements from RSS Item & Atom Entry
+type ItemV1 struct {
Link string `bare:"link"`
Title string `bare:"title"`
Content string `bare:"content"`
Read bool `bare:"read"`
Favorite bool `bare:"favorite"`
Date Timestamp `bare:"date"`
- Media *Media `bare:"media"`
+ Media *MediaV1 `bare:"media"`
}
// Decode will convert bytes into Item
-func (t *Item) Decode(data []byte) error {
+func (t *ItemV1) Decode(data []byte) error {
return bare.Unmarshal(data, t)
}
// Encode will convert Item into bytes
-func (t *Item) Encode() ([]byte, error) {
+func (t *ItemV1) Encode() ([]byte, error) {
return bare.Marshal(t)
}
-// Media contains info needed for a podcast
-type Media struct {
+// MediaV1 contains info needed for a podcast
+type MediaV1 struct {
Location string `bare:"location"`
Mimetype string `bare:"mimetype"`
Length int64 `bare:"length"`
@@ 84,27 84,15 @@ type Media struct {
}
// Decode will convert bytes into Media
-func (t *Media) Decode(data []byte) error {
+func (t *MediaV1) Decode(data []byte) error {
return bare.Unmarshal(data, t)
}
// Encode will convert Media into bytes
-func (t *Media) Encode() ([]byte, error) {
+func (t *MediaV1) Encode() ([]byte, error) {
return bare.Marshal(t)
}
-// Message it the root type of a barefeed. It allows for future versions of the
-// spec and allowing backward compatability
-type Message interface {
- bare.Union
-}
-
// IsUnion function is necessary to make the type compatible with the Union
// interface
func (t MessageV1) IsUnion() {}
-
-func init() {
- bare.RegisterUnion((*Message)(nil)).
- Member(*new(MessageV1), 0)
-
-}