Skip to content

Commit d185ae4

Browse files
golint compliant and more idiomatic.
1 parent 9137d43 commit d185ae4

3 files changed

Lines changed: 9 additions & 9 deletions

File tree

chapter2/sample/matchers/rss.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ func init() {
7070
func (m rssMatcher) Search(feed *search.Feed, searchTerm string) ([]*search.Result, error) {
7171
var results []*search.Result
7272

73-
log.Printf("Search Feed Type[%s] Site[%s] For Uri[%s]\n", feed.Type, feed.Name, feed.Uri)
73+
log.Printf("Search Feed Type[%s] Site[%s] For Uri[%s]\n", feed.Type, feed.Name, feed.URI)
7474

7575
// Retrieve the data to search.
7676
document, err := m.retrieve(feed)
@@ -113,12 +113,12 @@ func (m rssMatcher) Search(feed *search.Feed, searchTerm string) ([]*search.Resu
113113

114114
// retrieve performs a HTTP Get request for the rss feed and decodes the results.
115115
func (m rssMatcher) retrieve(feed *search.Feed) (*rssDocument, error) {
116-
if feed.Uri == "" {
116+
if feed.URI == "" {
117117
return nil, errors.New("No rss feed uri provided")
118118
}
119119

120120
// Retrieve the rss feed document from the web.
121-
resp, err := http.Get(feed.Uri)
121+
resp, err := http.Get(feed.URI)
122122
if err != nil {
123123
return nil, err
124124
}

chapter2/sample/search/feed.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ const dataFile = "data/data.json"
1010
// Feed contains information we need to process a feed.
1111
type Feed struct {
1212
Name string `json:"site"`
13-
Uri string `json:"link"`
13+
URI string `json:"link"`
1414
Type string `json:"type"`
1515
}
1616

1717
// RetrieveFeeds reads and unmarshals the feed data file.
18-
func RetrieveFeeds() ([]*Feed, error) {
18+
func RetrieveFeeds() ([]Feed, error) {
1919
// Open the file.
2020
file, err := os.Open(dataFile)
2121
if err != nil {
@@ -28,7 +28,7 @@ func RetrieveFeeds() ([]*Feed, error) {
2828

2929
// Decode the file into a slice of pointers
3030
// to Feed values.
31-
var feeds []*Feed
31+
var feeds []Feed
3232
err = json.NewDecoder(file).Decode(&feeds)
3333

3434
// We don't need to check for errors, the caller can do this.

chapter2/sample/search/search.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
)
77

88
// A map of registered matchers for searching.
9-
var matchers map[string]Matcher = make(map[string]Matcher)
9+
var matchers = make(map[string]Matcher)
1010

1111
// Run performs the search logic.
1212
func Run(searchTerm string) {
@@ -35,8 +35,8 @@ func Run(searchTerm string) {
3535
}
3636

3737
// Launch the goroutine to perform the search.
38-
go func(matcher Matcher, feed *Feed) {
39-
Match(matcher, feed, searchTerm, results)
38+
go func(matcher Matcher, feed Feed) {
39+
Match(matcher, &feed, searchTerm, results)
4040
waitGroup.Done()
4141
}(matcher, feed)
4242
}

0 commit comments

Comments
 (0)