🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more

github.com/konishchevdmitry/go-rss

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/konishchevdmitry/go-rss

v0.0.0-20191207114205-40a828964875
Version published
Created

Simple RSS parser and generator for Go

Usage example:

package main

import (
    "fmt"
    "github.com/KonishchevDmitry/go-rss"
)

var rssData = `
<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
    <channel>
        <title>Feed title</title>
        <link>http://example.com/</link>
        <description>Feed description</description>
        <item>
            <title>Item 1</title>
            <link>http://example.com/item1</link>
            <description>Item 1 description</description>
        </item>
    </channel>
</rss>
`

func main() {
    url := "http://example.com/feed.rss"

    // Get an RSS feed from URL
    feed, err := rss.Get(url)
    if err != nil {
        fmt.Printf("Failed to get %s: %s\n", url, err)
    }

    // Get an RSS feed from string
    feed, err = rss.Parse([]byte(rssData))
    if err != nil {
        fmt.Println("Parsing error:", err)
        return
    }

    // Change <generator> element value
    feed.Generator = "go-rss"

    // Generate the modified RSS feed
    data, err := rss.Generate(feed)
    if err != nil {
        fmt.Println("RSS generation error:", err)
        return
    }

    fmt.Printf("%s\n", data)
}

Output:

<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
    <channel>
        <title>Feed title</title>
        <link>http://example.com/</link>
        <description>Feed description</description>
        <generator>go-rss</generator>
        <item>
            <title>Item 1</title>
            <link>http://example.com/item1</link>
            <description>Item 1 description</description>
        </item>
    </channel>
</rss>

FAQs

Package last updated on 07 Dec 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts