Missing handlers but there we goddamn GO

Former-commit-id: 2505146a54acaf18eadfdebf1dd2720889aef795
This commit is contained in:
bel
2019-06-22 16:23:27 -06:00
parent 093d468f87
commit 35b3ff2c2d
24 changed files with 216 additions and 37 deletions

52
handlers/handler.go Normal file
View File

@@ -0,0 +1,52 @@
package handlers
import (
"local/rssmon3/config"
"local/rssmon3/monitor"
"local/rssmon3/rss"
"log"
)
type Handler struct {
Jobs <-chan *monitor.Item
config.Stoppable
}
func New(jobs <-chan *monitor.Item) *Handler {
return &Handler{
Jobs: jobs,
}
}
func (h *Handler) Run() error {
for {
select {
case <-h.Stopped():
return nil
case j := <-h.Jobs:
go func(key string) {
if err := h.Job(key); err != nil {
log.Println(err)
}
}(j.Key)
}
}
}
func (h *Handler) Job(key string) error {
f := &rss.Feed{Key: key}
if err := f.Load(); err != nil {
return err
}
if err := f.Pull(); err != nil {
return err
}
for _, tag := range f.Tags {
if foo := ByTag(tag); foo != nil {
if err := foo(key); err != nil {
return err
}
}
}
return nil
}

12
handlers/lookup.go Normal file
View File

@@ -0,0 +1,12 @@
package handlers
func ByTag(tag string) func(string) error {
var foo func(string) error
switch tag {
case "torrent":
foo = torrent
case "podcast":
foo = podcast
}
return foo
}

7
handlers/podcast.go Normal file
View File

@@ -0,0 +1,7 @@
package handlers
import "errors"
func podcast(key string) error {
return errors.New("not impl")
}

7
handlers/torrent.go Normal file
View File

@@ -0,0 +1,7 @@
package handlers
import "errors"
func torrent(key string) error {
return errors.New("not impl")
}