dir2opds/opds/feed_builder.go

48 lines
1.1 KiB
Go
Raw Normal View History

package opds
2017-05-11 23:06:21 +00:00
import (
2018-03-03 20:12:41 +00:00
"time"
2017-05-11 23:06:21 +00:00
"github.com/lann/builder"
"golang.org/x/tools/blog/atom"
)
2021-05-06 06:48:02 +00:00
type AcquisitionFeed struct {
*atom.Feed
Dc string `xml:"xmlns:dc,attr"`
Opds string `xml:"xmlns:opds,attr"`
}
2017-05-11 23:06:21 +00:00
type feedBuilder builder.Builder
func (f feedBuilder) Title(title string) feedBuilder {
return builder.Set(f, "Title", title).(feedBuilder)
}
2018-03-03 20:12:41 +00:00
func (f feedBuilder) ID(id string) feedBuilder {
2017-05-11 23:06:21 +00:00
return builder.Set(f, "ID", id).(feedBuilder)
}
func (f feedBuilder) AddLink(link atom.Link) feedBuilder {
return builder.Append(f, "Link", link).(feedBuilder)
}
func (f feedBuilder) Updated(updated time.Time) feedBuilder {
return builder.Set(f, "Updated", atom.Time(updated)).(feedBuilder)
}
func (f feedBuilder) Author(author atom.Person) feedBuilder {
return builder.Set(f, "Author", &author).(feedBuilder)
}
func (f feedBuilder) AddEntry(entry atom.Entry) feedBuilder {
return builder.Append(f, "Entry", &entry).(feedBuilder)
}
func (f feedBuilder) Build() atom.Feed {
return builder.GetStruct(f).(atom.Feed)
}
2018-03-03 20:12:41 +00:00
// FeedBuilder is a fluent immutable builder to build OPDS Feeds
2017-05-11 23:06:21 +00:00
var FeedBuilder = builder.Register(feedBuilder{}, atom.Feed{}).(feedBuilder)