File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -9,6 +9,21 @@ import (
99 "github.com/goinaction/code/src/chapter2/search/rss"
1010)
1111
12+ // NewMatcher is a factory that creates matcher values based
13+ // on the type of feed specified.
14+ func NewMatcher (feed data.Feed ) search.Matcher {
15+ // Create the right type of matcher for this search.
16+ switch feed .Type {
17+ case "rss" :
18+ return rss .NewMatcher (& feed )
19+
20+ // TODO: Add new Matchers here
21+ }
22+
23+ log .Fatalln ("Invalid Feed Type" )
24+ return nil
25+ }
26+
1227// main is the entry point for the program.
1328func main () {
1429 // Search term we are looking for.
@@ -29,16 +44,8 @@ func main() {
2944
3045 // Launch a goroutine for each feed to find the results.
3146 for _ , feed := range feeds {
32- var matcher search.Matcher
33-
34- // Create the right type of matcher for this search.
35- switch feed .Type {
36- case "rss" :
37- matcher = rss .NewMatcher (feed )
38-
39- default :
40- log .Fatalln ("Invalid Feed Type" )
41- }
47+ // Create a matcher for the search.
48+ matcher := NewMatcher (feed )
4249
4350 // Launch the goroutine to perform the search.
4451 go func () {
Original file line number Diff line number Diff line change 6262)
6363
6464// NewMatcher creates a value of matcher for use.
65- func NewMatcher (feed data.Feed ) feed.Matcher {
65+ func NewMatcher (feed * data.Feed ) feed.Matcher {
6666 return & matcher {
67- Feed : & feed ,
67+ Feed : feed ,
6868 }
6969}
7070
You can’t perform that action at this time.
0 commit comments