title | keywords | description | ||
---|---|---|---|---|
RSS Feed |
|
Generating an RSS feed. |
This project demonstrates how to create an RSS feed in a Go application using the Fiber framework.
Ensure you have the following installed:
- Golang
- Fiber package
-
Clone the repository:
git clone https://github.com/gofiber/recipes.git cd recipes/rss-feed
-
Install dependencies:
go get
- Start the application:
go run main.go
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")
}