Problem: HubBackend depends on ProcessContent in memorybackend
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
Solution: Create interface for memorybackend and depend on that.
This commit is contained in:
parent
5d5ee63d68
commit
a75bbb2551
|
@ -82,7 +82,8 @@ func NewApp(options AppOptions) (*App, error) {
|
||||||
http.Handle("/microsub", handler)
|
http.Handle("/microsub", handler)
|
||||||
|
|
||||||
http.Handle("/incoming/", &incomingHandler{
|
http.Handle("/incoming/", &incomingHandler{
|
||||||
Backend: app.hubBackend,
|
Backend: app.hubBackend,
|
||||||
|
Processor: app.backend,
|
||||||
})
|
})
|
||||||
|
|
||||||
if !options.Headless {
|
if !options.Headless {
|
||||||
|
|
|
@ -23,7 +23,7 @@ type HubBackend interface {
|
||||||
Feeds() ([]Feed, error)
|
Feeds() ([]Feed, error)
|
||||||
CreateFeed(url string) (int64, error)
|
CreateFeed(url string) (int64, error)
|
||||||
GetSecret(feedID int64) string
|
GetSecret(feedID int64) string
|
||||||
UpdateFeed(feedID int64, contentType string, body io.Reader) error
|
UpdateFeed(processor ContentProcessor, feedID int64, contentType string, body io.Reader) error
|
||||||
FeedSetLeaseSeconds(feedID int64, leaseSeconds int64) error
|
FeedSetLeaseSeconds(feedID int64, leaseSeconds int64) error
|
||||||
Subscribe(feed *Feed) error
|
Subscribe(feed *Feed) error
|
||||||
}
|
}
|
||||||
|
@ -114,7 +114,7 @@ VALUES ($1, $2, $3, $4, DEFAULT) RETURNING "id"`, topic, secret, urlSecret, 60*6
|
||||||
return int64(subscriptionID), nil
|
return int64(subscriptionID), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *hubIncomingBackend) UpdateFeed(subscriptionID int64, contentType string, body io.Reader) error {
|
func (h *hubIncomingBackend) UpdateFeed(processor ContentProcessor, subscriptionID int64, contentType string, body io.Reader) error {
|
||||||
log.Println("UpdateFeed", subscriptionID)
|
log.Println("UpdateFeed", subscriptionID)
|
||||||
|
|
||||||
db := h.database
|
db := h.database
|
||||||
|
@ -141,7 +141,7 @@ func (h *hubIncomingBackend) UpdateFeed(subscriptionID int64, contentType string
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Printf("Updating feed %s %q in %q\n", feedID, topic, channel)
|
log.Printf("Updating feed %s %q in %q\n", feedID, topic, channel)
|
||||||
err = h.backend.ProcessContent(channel, feedID, topic, contentType, body)
|
err = processor.ProcessContent(channel, feedID, topic, contentType, body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("could not process content for channel %s: %s", channel, err)
|
log.Printf("could not process content for channel %s: %s", channel, err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,8 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type incomingHandler struct {
|
type incomingHandler struct {
|
||||||
Backend HubBackend
|
Backend HubBackend
|
||||||
|
Processor ContentProcessor
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -94,7 +95,7 @@ func (h *incomingHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
ct := r.Header.Get("Content-Type")
|
ct := r.Header.Get("Content-Type")
|
||||||
err = h.Backend.UpdateFeed(feed, ct, bytes.NewBuffer(feedContent))
|
err = h.Backend.UpdateFeed(h.Processor, feed, ct, bytes.NewBuffer(feedContent))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, fmt.Sprintf("could not update feed: %s (%s)", ct, err), 400)
|
http.Error(w, fmt.Sprintf("could not update feed: %s (%s)", ct, err), 400)
|
||||||
return
|
return
|
||||||
|
|
|
@ -573,6 +573,11 @@ func ProcessSourcedItems(fetcher fetch.Fetcher, fetchURL, contentType string, bo
|
||||||
return items, nil
|
return items, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ContentProcessor processes content for a channel and feed
|
||||||
|
type ContentProcessor interface {
|
||||||
|
ProcessContent(channel, feedID, fetchURL, contentType string, body io.Reader) error
|
||||||
|
}
|
||||||
|
|
||||||
func (b *memoryBackend) ProcessContent(channel, feedID, fetchURL, contentType string, body io.Reader) error {
|
func (b *memoryBackend) ProcessContent(channel, feedID, fetchURL, contentType string, body io.Reader) error {
|
||||||
cachingFetch := WithCaching(b.pool, fetch.FetcherFunc(Fetch2))
|
cachingFetch := WithCaching(b.pool, fetch.FetcherFunc(Fetch2))
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user