40 lines
599 B
Go
40 lines
599 B
Go
|
package feed
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
"time"
|
||
|
|
||
|
"github.com/gorilla/feeds"
|
||
|
)
|
||
|
|
||
|
type Feed struct {
|
||
|
*feeds.Feed
|
||
|
}
|
||
|
|
||
|
func NewFeed(title, link, desc string) Feed {
|
||
|
return Feed{
|
||
|
Feed: &feeds.Feed{
|
||
|
Title: title,
|
||
|
Link: &feeds.Link{Href: link},
|
||
|
Description: desc,
|
||
|
},
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func AddToFeed(feed Feed, title, content string) error {
|
||
|
item := feeds.Item{
|
||
|
Title: title,
|
||
|
Created: time.Now(),
|
||
|
Content: content,
|
||
|
}
|
||
|
feed.Add(&item)
|
||
|
|
||
|
rss, err := feed.ToRss()
|
||
|
if err != nil {
|
||
|
return fmt.Errorf("error cmd/feed/rss.go AddToFeed feed.ToRss(): %v", err)
|
||
|
}
|
||
|
fmt.Println(rss)
|
||
|
|
||
|
return nil
|
||
|
}
|