2013-12-05 14:30:26 +00:00
|
|
|
/*
|
|
|
|
Credits go to github.com/SlyMarbo/rss for inspiring this solution.
|
|
|
|
*/
|
|
|
|
package feeder
|
|
|
|
|
2014-10-04 11:45:05 +00:00
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
)
|
|
|
|
|
2013-12-05 14:30:26 +00:00
|
|
|
type database struct {
|
|
|
|
request chan string
|
|
|
|
response chan bool
|
|
|
|
known map[string]struct{}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *database) Run() {
|
|
|
|
d.known = make(map[string]struct{})
|
|
|
|
var s string
|
|
|
|
|
|
|
|
for {
|
|
|
|
s = <-d.request
|
|
|
|
if _, ok := d.known[s]; ok {
|
2014-10-04 11:45:05 +00:00
|
|
|
fmt.Println("Database used: true")
|
2013-12-05 14:30:26 +00:00
|
|
|
d.response <- true
|
|
|
|
} else {
|
2014-10-04 11:45:05 +00:00
|
|
|
fmt.Println("Database used: false")
|
2013-12-05 14:30:26 +00:00
|
|
|
d.response <- false
|
|
|
|
d.known[s] = struct{}{}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewDatabase() *database {
|
|
|
|
database := new(database)
|
|
|
|
database.request = make(chan string)
|
|
|
|
database.response = make(chan bool)
|
|
|
|
go database.Run()
|
|
|
|
return database
|
|
|
|
}
|