15
type SitemapTime time.Time
19
type FeedInterface interface {
20
setChannelData(FeedChannelData)
22
addFeedItem(*FeedItem)
25
type FeedGeneratorInterface interface {
27
AsXML() ([]byte, error)
41
type FeedItemList []*FeedItem
43
type FeedChannelData struct {
52
FeedItems FeedItemList
55
type Feed[F FeedInterface] struct {
59
func (ct SitemapTime) MarshalText() ([]byte, error) {
62
return []byte(t.Format(time.RFC3339)), nil
65
func (ct RssTime) MarshalText() ([]byte, error) {
68
return []byte(t.Format(time.RFC1123Z)), nil
71
func (d FeedChannelData) GIUD() string {
72
return byStringGIUD(d.Link)
75
func (i FeedItem) GIUD() (result string) {
76
dt := time.Date(2024, time.June, 8, 0, 0, 0, 0, time.UTC)
77
if dt.Before(i.CreatedAt) {
78
result = byStringGIUD(fmt.Sprintf("feed%d%d", i.ID, i.ID*i.ID))
80
result = byStringGIUD(i.Slug)
86
func CreateFeed[T FeedInterface](t T, d FeedChannelData) *Feed[T] {
87
feed := Feed[T]{value: t}
88
feed.value.setChannelData(d)
93
func (f Feed[T]) ContentType() string {
94
return f.value.ContentType()
97
func (f Feed[T]) AsXML() ([]byte, error) {
98
return xml.MarshalIndent(f.value, "", " ")
101
func byStringGIUD(s string) string {
103
hash.Write([]byte(s))
106
return fmt.Sprintf("%x-%x-%x-%x-%x", sum[0:4], sum[4:6], sum[6:8], sum[8:10], sum[10:16])