Refactor RSSFeedHandler function to generate RSS feed with dynamic title and link
This commit is contained in:
parent
caa3833178
commit
b975ddb9e5
1 changed files with 6 additions and 8 deletions
14
api/rss.go
14
api/rss.go
|
@ -1,7 +1,6 @@
|
|||
package api
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
|
@ -13,11 +12,6 @@ import (
|
|||
)
|
||||
|
||||
func RSSFeedHandler(c echo.Context) error {
|
||||
feed := &feeds.Feed{
|
||||
Title: "Goth Stack Sample Blog",
|
||||
Link: &feeds.Link{Href: "https://goth-stack.fly.dev/"},
|
||||
}
|
||||
|
||||
files, err := os.ReadDir("./content/")
|
||||
|
||||
protocol := "http"
|
||||
|
@ -25,6 +19,11 @@ func RSSFeedHandler(c echo.Context) error {
|
|||
protocol = "https"
|
||||
}
|
||||
|
||||
feed := &feeds.Feed{
|
||||
Title: "GOTH Stack Demo Blog",
|
||||
Link: &feeds.Link{Href: protocol + "://" + c.Request().Host + "/api/rss"},
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
http.Error(c.Response().Writer, "There was an issue finding posts!", http.StatusInternalServerError)
|
||||
return nil
|
||||
|
@ -47,6 +46,5 @@ func RSSFeedHandler(c echo.Context) error {
|
|||
}
|
||||
|
||||
rss, _ := feed.ToRss()
|
||||
fmt.Println("RSS:", rss)
|
||||
return c.String(http.StatusOK, rss)
|
||||
return c.Blob(http.StatusOK, "application/rss+xml", []byte(rss))
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue