Skip to content

Commit 9552fa0

Browse files
Changed type name from Search To Feed and added New function
1 parent 5f036f4 commit 9552fa0

2 files changed

Lines changed: 11 additions & 7 deletions

File tree

‎src/chapter2/search/main.go‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,7 @@ func main() {
4242
// Create the right type of matcher for this search.
4343
switch site.Type {
4444
case "rss":
45-
matcher = &rss.Search{
46-
Site: site,
47-
}
45+
matcher = rss.New(site)
4846

4947
default:
5048
log.Fatalln("Invalid Type")

‎src/chapter2/search/rss/rss.go‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,19 @@ type (
5656

5757
type (
5858
// Implements the Matcher interface.
59-
Search struct {
60-
Site feeds.Site
59+
Feed struct {
60+
Site *feeds.Site
6161
}
6262
)
6363

64+
func New(site feeds.Site) *Feed {
65+
return &Feed{
66+
Site: &site,
67+
}
68+
}
69+
6470
// Match looks at the document for the specified search term.
65-
func (s *Search) Match(searchTerm string) ([]find.Result, error) {
71+
func (s *Feed) Match(searchTerm string) ([]find.Result, error) {
6672
var results []find.Result
6773

6874
log.Printf("Search Feed Type[%s] Site[%s] For Uri[%s]\n", s.Site.Type, s.Site.Name, s.Site.Uri)
@@ -107,7 +113,7 @@ func (s *Search) Match(searchTerm string) ([]find.Result, error) {
107113
}
108114

109115
// retrieve performs a HTTP Get request for the rss feed and unmarshals the results.
110-
func (s *Search) retrieve() (*Document, error) {
116+
func (s *Feed) retrieve() (*Document, error) {
111117
if s.Site.Uri == "" {
112118
return nil, errors.New("No RSS Feed Uri Provided")
113119
}

0 commit comments

Comments
 (0)