|
1 | 1 | ## gorilla/feeds
|
| 2 | +[](https://godoc.org/github.com/gorilla/feeds) [](https://travis-ci.org/gorilla/feeds) |
2 | 3 |
|
3 |
| -Web feed generator library. |
4 |
| - |
5 |
| -[](https://travis-ci.org/gorilla/feeds) |
| 4 | +feeds is a web feed generator library for generating RSS and Atom feeds from Go |
| 5 | +applications. |
6 | 6 |
|
7 | 7 | ### Goals
|
8 | 8 |
|
9 |
| - * simple interface to create both Atom & RSS 2.0 feeds |
10 |
| - * full support for Atom/RSS2.0 spec elements |
11 |
| - * ability to modify particulars for each spec |
| 9 | + * Provide a simple interface to create both Atom & RSS 2.0 feeds |
| 10 | + * Full support for Atom and RSS2.0 spec elements |
| 11 | + * Ability to modify particulars for each spec |
12 | 12 |
|
13 | 13 | ### Usage
|
14 | 14 |
|
15 | 15 | ```go
|
| 16 | +package main |
16 | 17 |
|
17 | 18 | import (
|
18 | 19 | "fmt"
|
19 | 20 | "time"
|
20 | 21 | "github.com/gorilla/feeds"
|
21 | 22 | )
|
22 | 23 |
|
23 |
| -now := time.Now() |
24 |
| -feed := &feeds.Feed{ |
25 |
| - Title: "jmoiron.net blog", |
26 |
| - Link: &feeds.Link{Href: "http://jmoiron.net/blog"}, |
27 |
| - Description: "discussion about tech, footie, photos", |
28 |
| - Author: &feeds. Author{ "Jason Moiron", "[email protected]"}, |
29 |
| - Created: now, |
30 |
| -} |
31 |
| - |
32 |
| -feed.Items = []*feeds.Item{ |
33 |
| - &feeds.Item{ |
34 |
| - Title: "Limiting Concurrency in Go", |
35 |
| - Link: &feeds.Link{Href: "http://jmoiron.net/blog/limiting-concurrency-in-go/"}, |
36 |
| - Description: "A discussion on controlled parallelism in golang", |
| 24 | +func main() { |
| 25 | + now := time.Now() |
| 26 | + feed := &feeds.Feed{ |
| 27 | + Title: "jmoiron.net blog", |
| 28 | + Link: &feeds.Link{Href: "http://jmoiron.net/blog"}, |
| 29 | + Description: "discussion about tech, footie, photos", |
37 | 30 | Author: &feeds. Author{ "Jason Moiron", "[email protected]"},
|
38 | 31 | Created: now,
|
39 |
| - }, |
40 |
| - &feeds.Item{ |
41 |
| - Title: "Logic-less Template Redux", |
42 |
| - Link: &feeds.Link{Href: "http://jmoiron.net/blog/logicless-template-redux/"}, |
43 |
| - Description: "More thoughts on logicless templates", |
44 |
| - Created: now, |
45 |
| - }, |
46 |
| - &feeds.Item{ |
47 |
| - Title: "Idiomatic Code Reuse in Go", |
48 |
| - Link: &feeds.Link{Href: "http://jmoiron.net/blog/idiomatic-code-reuse-in-go/"}, |
49 |
| - Description: "How to use interfaces <em>effectively</em>", |
50 |
| - Created: now, |
51 |
| - }, |
| 32 | + } |
| 33 | + |
| 34 | + feed.Items = []*feeds.Item{ |
| 35 | + &feeds.Item{ |
| 36 | + Title: "Limiting Concurrency in Go", |
| 37 | + Link: &feeds.Link{Href: "http://jmoiron.net/blog/limiting-concurrency-in-go/"}, |
| 38 | + Description: "A discussion on controlled parallelism in golang", |
| 39 | + Author: &feeds. Author{ "Jason Moiron", "[email protected]"}, |
| 40 | + Created: now, |
| 41 | + }, |
| 42 | + &feeds.Item{ |
| 43 | + Title: "Logic-less Template Redux", |
| 44 | + Link: &feeds.Link{Href: "http://jmoiron.net/blog/logicless-template-redux/"}, |
| 45 | + Description: "More thoughts on logicless templates", |
| 46 | + Created: now, |
| 47 | + }, |
| 48 | + &feeds.Item{ |
| 49 | + Title: "Idiomatic Code Reuse in Go", |
| 50 | + Link: &feeds.Link{Href: "http://jmoiron.net/blog/idiomatic-code-reuse-in-go/"}, |
| 51 | + Description: "How to use interfaces <em>effectively</em>", |
| 52 | + Created: now, |
| 53 | + }, |
| 54 | + } |
| 55 | + |
| 56 | + atom, err := feed.ToAtom() |
| 57 | + if err != nil { |
| 58 | + log.Fatal(err) |
| 59 | + } |
| 60 | + |
| 61 | + rss, err := feed.ToRss() |
| 62 | + if err != nil { |
| 63 | + log.Fatal(err) |
| 64 | + } |
| 65 | + |
| 66 | + fmt.Println(atom, "\n", rss) |
52 | 67 | }
|
53 |
| - |
54 |
| -atom, err := feed.ToAtom() |
55 |
| -rss, err := feed.ToRss() |
56 |
| - |
57 |
| -fmt.Println(atom, "\n", rss) |
58 |
| - |
59 | 68 | ```
|
60 | 69 |
|
61 | 70 | Outputs:
|
|
0 commit comments