doc.go (2320B)
1 /* 2 Syndication (feed) generator library for golang. 3 4 Installing 5 6 go get github.com/gorilla/feeds 7 8 Feeds provides a simple, generic Feed interface with a generic Item object as well as RSS, Atom and JSON Feed specific RssFeed, AtomFeed and JSONFeed objects which allow access to all of each spec's defined elements. 9 10 Examples 11 12 Create a Feed and some Items in that feed using the generic interfaces: 13 14 import ( 15 "time" 16 . "github.com/gorilla/feeds" 17 ) 18 19 now = time.Now() 20 21 feed := &Feed{ 22 Title: "jmoiron.net blog", 23 Link: &Link{Href: "http://jmoiron.net/blog"}, 24 Description: "discussion about tech, footie, photos", 25 Author: &Author{Name: "Jason Moiron", Email: "jmoiron@jmoiron.net"}, 26 Created: now, 27 Copyright: "This work is copyright © Benjamin Button", 28 } 29 30 feed.Items = []*Item{ 31 &Item{ 32 Title: "Limiting Concurrency in Go", 33 Link: &Link{Href: "http://jmoiron.net/blog/limiting-concurrency-in-go/"}, 34 Description: "A discussion on controlled parallelism in golang", 35 Author: &Author{Name: "Jason Moiron", Email: "jmoiron@jmoiron.net"}, 36 Created: now, 37 }, 38 &Item{ 39 Title: "Logic-less Template Redux", 40 Link: &Link{Href: "http://jmoiron.net/blog/logicless-template-redux/"}, 41 Description: "More thoughts on logicless templates", 42 Created: now, 43 }, 44 &Item{ 45 Title: "Idiomatic Code Reuse in Go", 46 Link: &Link{Href: "http://jmoiron.net/blog/idiomatic-code-reuse-in-go/"}, 47 Description: "How to use interfaces <em>effectively</em>", 48 Created: now, 49 }, 50 } 51 52 From here, you can output Atom, RSS, or JSON Feed versions of this feed easily 53 54 atom, err := feed.ToAtom() 55 rss, err := feed.ToRss() 56 json, err := feed.ToJSON() 57 58 You can also get access to the underlying objects that feeds uses to export its XML 59 60 atomFeed := (&Atom{Feed: feed}).AtomFeed() 61 rssFeed := (&Rss{Feed: feed}).RssFeed() 62 jsonFeed := (&JSON{Feed: feed}).JSONFeed() 63 64 From here, you can modify or add each syndication's specific fields before outputting 65 66 atomFeed.Subtitle = "plays the blues" 67 atom, err := ToXML(atomFeed) 68 rssFeed.Generator = "gorilla/feeds v1.0 (github.com/gorilla/feeds)" 69 rss, err := ToXML(rssFeed) 70 jsonFeed.NextUrl = "https://www.example.com/feed.json?page=2" 71 json, err := jsonFeed.ToJSON() 72 */ 73 package feeds