xesite/vendor/github.com/Xe/jsonfeed/jsonfeed.go

74 lines
2.0 KiB
Go
Raw Normal View History

2017-05-20 22:43:42 +00:00
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/
package jsonfeed
import (
"encoding/json"
"io"
"time"
)
const CurrentVersion = "https://jsonfeed.org/version/1"
type Item struct {
2017-12-13 18:43:58 +00:00
ID string `json:"id"`
URL string `json:"url"`
ExternalURL string `json:"external_url"`
Title string `json:"title"`
ContentHTML string `json:"content_html"`
ContentText string `json:"content_text"`
Summary string `json:"summary"`
Image string `json:"image"`
BannerImage string `json:"banner_image"`
DatePublished time.Time `json:"date_published"`
DateModified time.Time `json:"date_modified"`
Author Author `json:"author"`
Tags []string `json:"tags"`
2017-05-20 22:43:42 +00:00
}
type Author struct {
2017-12-13 18:43:58 +00:00
Name string `json:"name"`
URL string `json:"url"`
Avatar string `json:"avatar"`
2017-05-20 22:43:42 +00:00
}
type Hub struct {
Type string `json:"type"`
URL string `json:"url"`
}
type Attachment struct {
2017-12-13 18:43:58 +00:00
URL string `json:"url"`
MIMEType string `json:"mime_type"`
Title string `json:"title"`
SizeInBytes int64 `json:"size_in_bytes"`
DurationInSeconds int64 `json:"duration_in_seconds"`
2017-05-20 22:43:42 +00:00
}
type Feed struct {
2017-12-13 18:43:58 +00:00
Version string `json:"version"`
Title string `json:"title"`
HomePageURL string `json:"home_page_url"`
FeedURL string `json:"feed_url"`
Description string `json:"description"`
UserComment string `json:"user_comment"`
NextURL string `json:"next_url"`
Icon string `json:"icon"`
Favicon string `json:"favicon"`
Author Author `json:"author"`
Expired bool `json:"expired"`
Hubs []Hub `json:"hubs"`
Items []Item `json:"items"`
2017-05-20 22:43:42 +00:00
}
func Parse(r io.Reader) (Feed, error) {
var feed Feed
decoder := json.NewDecoder(r)
if err := decoder.Decode(&feed); err != nil {
return Feed{}, err
}
return feed, nil
}