RSS Feed
This project demonstrates how to create an RSS feed in a Go application using the Fiber framework.
Prerequisites
Ensure you have the following installed:
- Golang
- Fiber package
Setup
-
Clone the repository:
git clone https://github.com/gofiber/recipes.gitcd recipes/rss-feed -
Install dependencies:
go get
Running the Application
- Start the application:
go run main.go
Example
This recipe uses Mustache templates (via the gofiber/template/mustache engine) to render an RSS XML response. The template lives in ./xmls/example.xml.
xmls/example.xml:
<?xml version="1.0" encoding="UTF-8"?>
<note>
<language>{{{Lang}}}</language>
<title>{{{Title}}}</title>
<greeting>{{{Greetings}}}</greeting>
</note>
main.go:
package main
import (
"log"
"github.com/gofiber/fiber/v3"
"github.com/gofiber/template/mustache/v3"
)
func main() {
engineXML := mustache.New("./xmls", ".xml")
if err := engineXML.Load(); err != nil {
log.Fatal(err)
}
app := fiber.New()
app.Get("/rss", func(c fiber.Ctx) error {
// Set Content-Type to application/rss+xml
c.Type("rss")
// Render Mustache template with data
return engineXML.Render(c, "example", fiber.Map{
"Lang": "en",
"Title": "hello-rss",
"Greetings": "Hello World",
})
})
log.Fatal(app.Listen(":3000"))
}
Testing with curl
curl http://localhost:3000/rss