mirror of
https://github.com/hanzoai/gateway.git
synced 2026-10-30 15:04:44 +00:00
Modules declare go 1.27.1 and the build images follow. go fix applied the modernizers; omitzero is not applied, since it changes what the JSON says. Co-authored-by: Hanzo Dev <[email protected]>
46 lines
1.0 KiB
Go
46 lines
1.0 KiB
Go
package rss
|
|
|
|
import (
|
|
"io"
|
|
|
|
"github.com/hanzoai/gateway/v2/internal/lura/encoding"
|
|
"github.com/mmcdole/gofeed"
|
|
)
|
|
|
|
func Register() error {
|
|
return encoding.GetRegister().Register(Name, DecoderFactory)
|
|
}
|
|
|
|
// Name is the key for the rss encoding
|
|
const Name = "rss"
|
|
|
|
func DecoderFactory(_ bool) func(io.Reader, *map[string]any) error { return NewDecoder() }
|
|
|
|
// NewDecoder returns the RSS decoder
|
|
func NewDecoder() func(io.Reader, *map[string]any) error {
|
|
fp := gofeed.NewParser()
|
|
return func(r io.Reader, v *map[string]any) error {
|
|
feed, err := fp.Parse(r)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
*(v) = map[string]any{
|
|
"items": feed.Items,
|
|
"author": feed.Author,
|
|
"categories": feed.Categories,
|
|
"custom": feed.Custom,
|
|
"copyright": feed.Copyright,
|
|
"description": feed.Description,
|
|
"type": feed.FeedType,
|
|
"language": feed.Language,
|
|
"title": feed.Title,
|
|
"published": feed.Published,
|
|
"updated": feed.Updated,
|
|
}
|
|
if feed.Image != nil {
|
|
(*v)["img_url"] = feed.Image.URL
|
|
}
|
|
return nil
|
|
}
|
|
}
|