A RSS feed valid in Go
For parsing a RSS feed, we gonna use the native library “encoding/xml” and define the good data structure of our futur XML file.
The base foundation
We begin with the node global “rss” and “channel” and the “xml.NewEncoder” function:
Then we add the node “item”:
Ok, but we need an array structure for “item”:
In a webserver
Let’s do this with a webserver and the “xml.MarshalIndent” function:
The good date format in “pubDate”
We need to use the “time” library with a valid format date RSS.
Let’s check with the official documentation: https://validator.w3.org/feed/docs/error/InvalidRFC2822Date.html
Then we can choose in Go a similar format date: http://golang.org/pkg/time/#pkg-constants
There is a matching with RFC1123Z:
Bonus: Markdown to HTML
If you have markdown syntax in your description, you will need to encode this syntax to HTML code. We gonna use Blackfriday library coded by Russ Ross:
go get github.com/russross/blackfriday
Then, we import this library in the code and we encode “Description” value to HTML format in a loop (“for range”):