Skip to content

Commit 738b6da

Browse files
More name refactoring
1 parent bff1f97 commit 738b6da

3 files changed

Lines changed: 19 additions & 19 deletions

File tree

‎src/chapter2/search/data/data.go‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,16 @@ const (
1111
)
1212

1313
type (
14-
// Site contains information about an rss feed.
15-
Site struct {
14+
// Feed contains information about an rss feed.
15+
Feed struct {
1616
Name string `json:"site"`
1717
Uri string `json:"link"`
1818
Type string `json:"type"`
1919
}
2020
)
2121

2222
// Load retrieves and unmarshals the data for the program.
23-
func Load() ([]Site, error) {
23+
func Load() ([]Feed, error) {
2424
// Get the current directory we are running inside.
2525
pwd, err := os.Getwd()
2626
if err != nil {
@@ -33,12 +33,12 @@ func Load() ([]Site, error) {
3333
return nil, err
3434
}
3535

36-
// Unmarshal the json document into a slice of sites.
37-
var sites []Site
38-
err = json.Unmarshal(data, &sites)
36+
// Unmarshal the json document into a slice of feeds.
37+
var feeds []Feed
38+
err = json.Unmarshal(data, &feeds)
3939
if err != nil {
4040
return nil, err
4141
}
4242

43-
return sites, nil
43+
return feeds, nil
4444
}

‎src/chapter2/search/main.go‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ func main() {
1414
// Search term we are looking for.
1515
searchTerm := "president"
1616

17-
// Load the feeds for the data file.
18-
sites, err := data.Load()
17+
// Load the feeds from the data file.
18+
feeds, err := data.Load()
1919
if err != nil {
2020
log.Fatal(err)
2121
}
@@ -25,16 +25,16 @@ func main() {
2525

2626
// Setup a wait group so we can process all the feeds.
2727
var waitGroup sync.WaitGroup
28-
waitGroup.Add(len(sites))
28+
waitGroup.Add(len(feeds))
2929

3030
// Launch a goroutine for each feed to find the results.
31-
for _, site := range sites {
31+
for _, data := range feeds {
3232
var matcher feed.Matcher
3333

3434
// Create the right type of matcher for this search.
35-
switch site.Type {
35+
switch data.Type {
3636
case "rss":
37-
matcher = rss.NewMatcher(site)
37+
matcher = rss.NewMatcher(data)
3838

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

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,22 +57,22 @@ type (
5757
type (
5858
// Implements the Matcher interface.
5959
matcher struct {
60-
Site *data.Site
60+
Feed *data.Feed
6161
}
6262
)
6363

6464
// NewMatcher creates a value of matcher for use.
65-
func NewMatcher(site data.Site) feed.Matcher {
65+
func NewMatcher(feed data.Feed) feed.Matcher {
6666
return &matcher{
67-
Site: &site,
67+
Feed: &feed,
6868
}
6969
}
7070

7171
// Match looks at the document for the specified search term.
7272
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", m.Site.Type, m.Site.Name, m.Site.Uri)
75+
log.Printf("Search Feed Type[%s] Site[%s] For Uri[%s]\n", m.Feed.Type, m.Feed.Name, m.Feed.Uri)
7676

7777
// Retrieve the data to search.
7878
document, err := m.retrieve()
@@ -115,12 +115,12 @@ func (m *matcher) Match(searchTerm string) ([]feed.Result, error) {
115115

116116
// retrieve performs a HTTP Get request for the rss feed and unmarshals the results.
117117
func (m *matcher) retrieve() (*document, error) {
118-
if m.Site.Uri == "" {
118+
if m.Feed.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(m.Site.Uri)
123+
resp, err := http.Get(m.Feed.Uri)
124124
if err != nil {
125125
return nil, err
126126
}

0 commit comments

Comments
 (0)