2024-09-13 03:03:39 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/xml"
|
2024-09-21 19:11:41 +00:00
|
|
|
"time"
|
2024-09-13 03:03:39 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type Document struct {
|
|
|
|
Channel Channel `xml:"channel"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type Item struct {
|
|
|
|
Title string `xml:"title"`
|
|
|
|
Link string `xml:"link"`
|
|
|
|
Description string `xml:"description"`
|
2024-09-21 19:11:41 +00:00
|
|
|
PubDate string `xml:"pubDate"`
|
|
|
|
PublishedDate time.Time
|
2024-09-13 03:03:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type Channel struct {
|
|
|
|
Title string `xml:"title"`
|
|
|
|
Description string `xml:"description"`
|
|
|
|
Items []Item `xml:"item"`
|
|
|
|
}
|
|
|
|
|
2024-09-21 19:11:41 +00:00
|
|
|
const DATE_FORMAT = "Mon, 02 Jan 2006 15:04:05 -0700"
|
2024-09-13 03:03:39 +00:00
|
|
|
|
2024-09-21 19:11:41 +00:00
|
|
|
func (i Item) GetPublishedDate() time.Time {
|
|
|
|
published, _ := time.Parse(DATE_FORMAT, i.PubDate)
|
|
|
|
return published
|
2024-09-13 03:03:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func ParseFeed(raw []byte) Document {
|
|
|
|
var doc Document
|
|
|
|
|
|
|
|
if err := xml.Unmarshal(raw, &doc); err != nil {
|
|
|
|
return Document{}
|
|
|
|
}
|
|
|
|
|
|
|
|
return doc
|
|
|
|
}
|