Skip to content

Latest commit

 

History

History
98 lines (75 loc) · 2.58 KB

README.md

File metadata and controls

98 lines (75 loc) · 2.58 KB
title keywords description
RSS Feed
rss
feed
Generating an RSS feed.

RSS Feed

Github StackBlitz

This project demonstrates how to create an RSS feed in a Go application using the Fiber framework.

Prerequisites

Ensure you have the following installed:

Setup

  1. Clone the repository:

    git clone https://github.com/gofiber/recipes.git
    cd recipes/rss-feed
  2. Install dependencies:

    go get

Running the Application

  1. Start the application:
    go run main.go

Example

Here is an example of how to create an RSS feed in a Fiber application:

package main

import (
    "github.com/gofiber/fiber/v2"
    "github.com/gorilla/feeds"
    "time"
)

func main() {
    app := fiber.New()

    app.Get("/rss", func(c *fiber.Ctx) error {
        feed := &feeds.Feed{
            Title:       "Example RSS Feed",
            Link:        &feeds.Link{Href: "http://example.com/rss"},
            Description: "This is an example RSS feed",
            Author:      &feeds.Author{Name: "John Doe", Email: "[email protected]"},
            Created:     time.Now(),
        }

        feed.Items = []*feeds.Item{
            {
                Title:       "First Post",
                Link:        &feeds.Link{Href: "http://example.com/post/1"},
                Description: "This is the first post",
                Author:      &feeds.Author{Name: "John Doe", Email: "[email protected]"},
                Created:     time.Now(),
            },
            {
                Title:       "Second Post",
                Link:        &feeds.Link{Href: "http://example.com/post/2"},
                Description: "This is the second post",
                Author:      &feeds.Author{Name: "Jane Doe", Email: "[email protected]"},
                Created:     time.Now(),
            },
        }

        rss, err := feed.ToRss()
        if err != nil {
            return err
        }

        c.Set("Content-Type", "application/rss+xml")
        return c.SendString(rss)
    })

    app.Listen(":3000")
}

References