Skip to content

Commit 6ebeec4

Browse files
Changed rss package for NewMatcher method and using an unexported type.
1 parent 5200134 commit 6ebeec4

2 files changed

Lines changed: 11 additions & 11 deletions

File tree

‎src/chapter2/search/main.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func main() {
3434
// Create the right type of matcher for this search.
3535
switch site.Type {
3636
case "rss":
37-
matcher = rss.New(site)
37+
matcher = rss.NewMatcher(site)
3838

3939
default:
4040
log.Fatalln("Invalid Type")

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

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

5757
type (
5858
// Implements the Matcher interface.
59-
Feed struct {
59+
matcher struct {
6060
Site *data.Site
6161
}
6262
)
6363

64-
// New creates a value of Feed for use.
65-
func New(site data.Site) *Feed {
66-
return &Feed{
64+
// NewMatcher creates a value of matcher for use.
65+
func NewMatcher(site data.Site) feed.Matcher {
66+
return &matcher{
6767
Site: &site,
6868
}
6969
}
7070

7171
// Match looks at the document for the specified search term.
72-
func (s *Feed) Match(searchTerm string) ([]feed.Result, error) {
72+
func (m *matcher) Match(searchTerm string) ([]feed.Result, error) {
7373
var results []feed.Result
7474

75-
log.Printf("Search Feed Type[%s] Site[%s] For Uri[%s]\n", s.Site.Type, s.Site.Name, s.Site.Uri)
75+
log.Printf("Search Feed Type[%s] Site[%s] For Uri[%s]\n", m.Site.Type, m.Site.Name, m.Site.Uri)
7676

7777
// Retrieve the data to search.
78-
document, err := s.retrieve()
78+
document, err := m.retrieve()
7979
if err != nil {
8080
return nil, err
8181
}
@@ -114,13 +114,13 @@ func (s *Feed) Match(searchTerm string) ([]feed.Result, error) {
114114
}
115115

116116
// retrieve performs a HTTP Get request for the rss feed and unmarshals the results.
117-
func (s *Feed) retrieve() (*Document, error) {
118-
if s.Site.Uri == "" {
117+
func (m *matcher) retrieve() (*Document, error) {
118+
if m.Site.Uri == "" {
119119
return nil, errors.New("No RSS Feed Uri Provided")
120120
}
121121

122122
// Retrieve the rss feed document from the web.
123-
resp, err := http.Get(s.Site.Uri)
123+
resp, err := http.Get(m.Site.Uri)
124124
if err != nil {
125125
return nil, err
126126
}

0 commit comments

Comments
 (0)