Fixes #44, crash when no handlers
Recent database handler changes made the library crash, when feed object is created without channel, item handlers (passing nils). These simple changes seem to fix the problem and the library works again.
This commit is contained in:
parent
c753ba0962
commit
1e531bd310
4
feed.go
4
feed.go
|
@ -46,13 +46,17 @@ func (err *UnsupportedFeedError) Error() string {
|
||||||
type ChannelHandlerFunc func(f *Feed, newchannels []*Channel)
|
type ChannelHandlerFunc func(f *Feed, newchannels []*Channel)
|
||||||
|
|
||||||
func (h ChannelHandlerFunc) ProcessChannels(f *Feed, newchannels []*Channel) {
|
func (h ChannelHandlerFunc) ProcessChannels(f *Feed, newchannels []*Channel) {
|
||||||
|
if h != nil {
|
||||||
h(f, newchannels)
|
h(f, newchannels)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type ItemHandlerFunc func(f *Feed, ch *Channel, newitems []*Item)
|
type ItemHandlerFunc func(f *Feed, ch *Channel, newitems []*Item)
|
||||||
|
|
||||||
func (h ItemHandlerFunc) ProcessItems(f *Feed, ch *Channel, newitems []*Item) {
|
func (h ItemHandlerFunc) ProcessItems(f *Feed, ch *Channel, newitems []*Item) {
|
||||||
|
if h != nil {
|
||||||
h(f, ch, newitems)
|
h(f, ch, newitems)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type Handler interface {
|
type Handler interface {
|
||||||
|
|
|
@ -29,6 +29,15 @@ func TestFeed(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Test_NoHandlers(t *testing.T) {
|
||||||
|
feed := New(1, true, nil, nil)
|
||||||
|
content, _ := ioutil.ReadFile("testdata/initial.atom")
|
||||||
|
err := feed.FetchBytes("http://example.com", content, nil)
|
||||||
|
if err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func Test_NewItem(t *testing.T) {
|
func Test_NewItem(t *testing.T) {
|
||||||
content, _ := ioutil.ReadFile("testdata/initial.atom")
|
content, _ := ioutil.ReadFile("testdata/initial.atom")
|
||||||
feed := New(1, true, chanHandler, itemHandler)
|
feed := New(1, true, chanHandler, itemHandler)
|
||||||
|
|
Loading…
Reference in New Issue