Documentation
¶
Overview ¶
Package feed2json converts Atom and RSS feeds to JSON feeds.
Index ¶
- func CLI(args []string) (err error)
- func Convert(from, to *bytes.Buffer) (err error)
- func ConvertObject(feed *gofeed.Feed) *feeds.JSONFeed
- func Handler(x URLExtractor, v URLValidator, c *http.Client, l Logger, ms ...Middleware) http.Handler
- type Logger
- type Middleware
- type URLExtractor
- type URLValidator
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Convert ¶
Convert takes an XML feed from one buffer and turns it into a JSON feed in the other buffer.
Example ¶
package main import ( "bytes" "encoding/json" "fmt" "github.com/carlmjohnson/feed2json" ) func main() { var from, to bytes.Buffer from.WriteString(` <?xml version="1.0"?> <rss version="2.0"> <channel> <title>Liftoff News</title> <link>http://liftoff.msfc.nasa.gov/</link> <description>Liftoff to Space Exploration.</description> <language>en-us</language> <pubDate>Tue, 10 Jun 2003 04:00:00 GMT</pubDate> <lastBuildDate>Tue, 10 Jun 2003 09:41:01 GMT</lastBuildDate> <docs>http://blogs.law.harvard.edu/tech/rss</docs> <generator>Weblog Editor 2.0</generator> <managingEditor>editor@example.com</managingEditor> <webMaster>webmaster@example.com</webMaster> <item> <title>Star City</title> <link>http://liftoff.msfc.nasa.gov/news/2003/news-starcity.asp</link> <description>How do Americans get ready to work with Russians aboard the International Space Station? They take a crash course in culture, language and protocol at Russia's <a href="http://howe.iki.rssi.ru/GCTC/gctc_e.htm">Star City</a>.</description> <pubDate>Tue, 03 Jun 2003 09:39:21 GMT</pubDate> <guid>http://liftoff.msfc.nasa.gov/2003/06/03.html#item573</guid> </item> </channel> </rss> `) if err := feed2json.Convert(&from, &to); err == nil { from.Reset() json.Indent(&from, to.Bytes(), "", " ") fmt.Println(from.String()) } }
Output: { "version": "https://jsonfeed.org/version/1", "title": "Liftoff News", "home_page_url": "http://liftoff.msfc.nasa.gov/", "description": "Liftoff to Space Exploration.", "author": {}, "items": [ { "id": "http://liftoff.msfc.nasa.gov/2003/06/03.html#item573", "url": "http://liftoff.msfc.nasa.gov/news/2003/news-starcity.asp", "title": "Star City", "content_html": "How do Americans get ready to work with Russians aboard the International Space Station? They take a crash course in culture, language and protocol at Russia's <a href=\"http://howe.iki.rssi.ru/GCTC/gctc_e.htm\">Star City</a>.", "date_published": "2003-06-03T09:39:21Z" } ] }
func ConvertObject ¶
ConvertObject converts a gofeed.Feed (used by the parser) into a gorilla/feeds.JSONFeed (used by the JSONFeed emitter).
func Handler ¶
func Handler(x URLExtractor, v URLValidator, c *http.Client, l Logger, ms ...Middleware) http.Handler
Types ¶
type URLExtractor ¶
func ExtractURLFromParam ¶
func ExtractURLFromParam(name string) URLExtractor
type URLValidator ¶
func ValidateHost ¶
func ValidateHost(names ...string) URLValidator
Click to show internal directories.
Click to hide internal directories.