~chrisppy/go-barefeed

41e72b3439193769242bfd2546b0ff61362ad632 — Chris Palmer 9 months ago 91a25b6
Updates due to schema change
4 files changed, 78 insertions(+), 17 deletions(-)

M .gitignore
M barefeed_test.go
M msg.go
M time.go
M .gitignore => .gitignore +1 -0
@@ 1,3 1,4 @@
*.test
*.prof
*.log
schema.bare

M barefeed_test.go => barefeed_test.go +8 -3
@@ 63,16 63,21 @@ func TestTimestamp(t *testing.T) {
}

func getTestMessage() Message {
	media := Media{
		Length:   int64(2),
		Position: int64(1),
		Location: "d",
		Mimetype: "e",
	}

	i := Item{
		Link:     "a",
		Title:    "b",
		Content:  "c",
		Location: "d",
		Mimetype: "e",
		Length:   "f",
		Read:     true,
		Favorite: true,
		Date:     ToTimestamp(time.Now()),
		Media:    &media,
	}

	f := Feed{

M msg.go => msg.go +69 -11
@@ 1,19 1,40 @@
package barefeed

// Code generated by go-bare/cmd/gen, DO NOT EDIT.

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

// MessageV1 is the first implementation of the barefeed message format
// Timestamp type to hold the UTC Unix value of time
type Timestamp int64

// Decode will convert bytes into Timestamp
func (t *Timestamp) Decode(data []byte) error {
	return bare.Unmarshal(data, t)
}

// Encode will convert Timestamp into bytes
func (t *Timestamp) Encode() ([]byte, error) {
	return bare.Marshal(t)
}

// MessageV1 is the first version of the spec
type MessageV1 struct {
	Created   Timestamp `bare:"created"`
	Generator string    `bare:"generator"`
	Feeds     []Feed    `bare:"feeds"`
}

// Feed contains all info needed for a RSS Feed
// Decode will convert bytes into MessageV1
func (t *MessageV1) Decode(data []byte) error {
	return bare.Unmarshal(data, t)
}

// Encode will convert MessageV1 into bytes
func (t *MessageV1) Encode() ([]byte, error) {
	return bare.Marshal(t)
}

// Feed type contains elements from RSS Channel & Atom Feed
type Feed struct {
	Feed        string `bare:"feed"`
	Title       string `bare:"title"`


@@ 22,26 43,63 @@ type Feed struct {
	Items       []Item `bare:"items"`
}

// Item contains all info needed for a RSS Item
// Decode will convert bytes into Feed
func (t *Feed) Decode(data []byte) error {
	return bare.Unmarshal(data, t)
}

// Encode will convert Feed into bytes
func (t *Feed) Encode() ([]byte, error) {
	return bare.Marshal(t)
}

// Item type contains elements from RSS Item & Atom Entry
type Item struct {
	Link     string    `bare:"link"`
	Title    string    `bare:"title"`
	Content  string    `bare:"content"`
	Location string    `bare:"location"`
	Mimetype string    `bare:"mimetype"`
	Length   string    `bare:"length"`
	Read     bool      `bare:"read"`
	Favorite bool      `bare:"favorite"`
	Date     Timestamp `bare:"date"`
	Media    *Media    `bare:"media"`
}

// Decode will convert bytes into Item
func (t *Item) Decode(data []byte) error {
	return bare.Unmarshal(data, t)
}

// Encode will convert Item into bytes
func (t *Item) Encode() ([]byte, error) {
	return bare.Marshal(t)
}

// Media contains info needed for a podcast
type Media struct {
	Location string `bare:"location"`
	Mimetype string `bare:"mimetype"`
	Length   int64  `bare:"length"`
	Position int64  `bare:"position"`
}

// Decode will convert bytes into Media
func (t *Media) Decode(data []byte) error {
	return bare.Unmarshal(data, t)
}

// Encode will convert Media into bytes
func (t *Media) Encode() ([]byte, error) {
	return bare.Marshal(t)
}

// Message is the core type for the barefeed message format. It will handle any
// new version that may be released
// 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 is necessary to make the type compatible with the Union interface
// IsUnion function is necessary to make the type compatible with the Union
// interface
func (_ MessageV1) IsUnion() {}

func init() {

M time.go => time.go +0 -3
@@ 4,9 4,6 @@ import (
	"time"
)

// Timestamp type
type Timestamp int64

// Time will convert the timestamp to time
func (t Timestamp) Time() time.Time {
	return time.Unix(int64(t), 0).UTC()