Sitemap
Canopas

We’re here to share knowledge and learnings about #android #iOS #web development. Follow Canopas to learn something new everyday.

How To Create RSS Feeds In Golang

--

RSS Feeds in Golang
RSS Feeds in Golang

Exciting News! Our blog has a new home! 🚀

In the era of digitalization, we have to keep our users up to date with frequently changing things in our applications.

One of the finest solutions is to use RSS(Really Simple Syndication) feeds.

What are RSS Feeds?

It is data or web feeds that allow users and applications to access regular updates from websites(from which they want updates) in a readable format.

Users have to subscribe to RSS Feeds for regular updates.

RSS Feeds are available in XML-formatted plain text.

Here is a sample XML format of the RSS feed.

<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title>RSS Feed's Title</title>
<description>Description of an RSS feed</description>
<link>http://www.rssfeedslink.com</link>
<copyright>All rights reserved</copyright>
<pubDate>Sat, 23 jan 2021 16:20:00 +0000</pubDate>

<item>
<title>First Item</title>
<description>Description Of Item</description>
<link>http://www.example.com/blog/post/1</link>
<pubDate>Sat, 23 jan 2021 16:20:00 +0000</pubDate>
</item>

</channel>
</rss>

You can find more about it from here

We will Create RSS feeds from JSON data In Golang.

We are using github.com/gorilla/feeds for generating RSS feeds.

You can also generate RSS feeds from the database data.

Let’s create RSS feeds.

First Create Main RSS feed data like below,

import "github.com/gorilla/feeds"feed := &feeds.Feed{
Title: "Title of Your Feeds",
Link: &feeds.Link{Href: "your feed link"},
Description: "Description of your feeds",
Author: &feeds.Author{Name: "author name"},
Created: time.Now(),
}

Then append items on a feed from selected database data using the following code.

var feedItems []*feeds.Itemfor i := 0; i < len(feedsData); i++ {         item := feedsData[i]       feedItems = append(feedItems,
&feeds.Item{
Id:item.ID,
Title:item.Title,
Link:&feeds.Link{Href: "feeds item link"},
Description:item.Description,
Created:time.Now(),
})
}
feed.Items = feedItems

Here you can append your data as per your requirements either in increasing or decreasing order.

Convert these feed items to original RSS Feeds using the RssFeed() method, and generate XML formatted feed

rssFeed := (&feeds.Rss{Feed: feed}).RssFeed()xmlRssFeeds := rssFeed.FeedXml()

That’s it. We can pass these data to API as well as web applications.

You can refer to the full source code here.

This blog post was originally published on canopas.com.

To read the full version, please visit this blog.

Thanks for your support!
If you like what you read, be sure to 👏 it below — as a writer it means the world!
Follow Canopas Software to get updates on interesting tech articles!

Keep Updating… 👍

--

--

Canopas
Canopas

Published in Canopas

We’re here to share knowledge and learnings about #android #iOS #web development. Follow Canopas to learn something new everyday.

Sumita K
Sumita K

Written by Sumita K

Web developer at Canopas | Write on various web technologies and cloud platforms.

No responses yet