forked from emmaly/go-pkg-rss
-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
databaseHandler.go
45 lines (40 loc) · 1.15 KB
/
databaseHandler.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package feeder
type databaseHandler struct {
db *database
itemhandler ItemHandler
chanhandler ChannelHandler
}
func (d *databaseHandler) ProcessItems(f *Feed, ch *Channel, items []*Item) {
var newitems []*Item
for _, item := range items {
if d.db.request <- item.Key(); !<-d.db.response {
newitems = append(newitems, item)
}
}
if len(newitems) > 0 && d.itemhandler != nil {
d.itemhandler.ProcessItems(f, ch, newitems)
}
}
func (d *databaseHandler) ProcessChannels(f *Feed, ch []*Channel) {
var newchannels []*Channel
for _, channel := range ch {
if d.db.request <- channel.Key(); !<-d.db.response {
newchannels = append(newchannels, channel)
}
}
if len(newchannels) > 0 && d.chanhandler != nil {
d.chanhandler.ProcessChannels(f, newchannels)
}
}
func NewDatabaseItemHandler(db *database, itemhandler ItemHandler) ItemHandler {
database := new(databaseHandler)
database.db = db
database.itemhandler = itemhandler
return database
}
func NewDatabaseChannelHandler(db *database, chanhandler ChannelHandler) ChannelHandler {
database := new(databaseHandler)
database.db = db
database.chanhandler = chanhandler
return database
}