Skip to content

Commit 81498a7

Browse files
Updated rss functions
1 parent 66d73f3 commit 81498a7

2 files changed

Lines changed: 9 additions & 9 deletions

File tree

‎src/chapter2/search/main.go‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,7 @@ func find(searchTerm string, site feeds.Site, captureResults chan []rss.SearchRe
5252
log.Printf("Search Feed Site[%s] For Uri[%s]\n", site.Name, site.Uri)
5353

5454
// Retrieve the RSS feed document.
55-
var document rss.Document
56-
err = rss.Retrieve(site.Uri, &document)
55+
document, err := rss.Retrieve(site.Uri)
5756
if err != nil {
5857
log.Printf("%s : %s", site.Uri, err)
5958
return

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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,34 +60,35 @@ type (
6060
)
6161

6262
// Retrieve performs a HTTP Get request for the rss feed and unmarshals the results.
63-
func Retrieve(uri string, document *Document) error {
63+
func Retrieve(uri string) (*Document, error) {
6464
if uri == "" {
65-
return errors.New("No RSS Feed Uri Provided")
65+
return nil, errors.New("No RSS Feed Uri Provided")
6666
}
6767

6868
// Retrieve the rss feed document from the web.
6969
resp, err := http.Get(uri)
7070
if err != nil {
71-
return err
71+
return nil, err
7272
}
7373

7474
// Close the response once we return from the function.
7575
defer resp.Body.Close()
7676

7777
// Unmarshal the document into our struct type.
78-
err = xml.NewDecoder(resp.Body).Decode(document)
78+
var document Document
79+
err = xml.NewDecoder(resp.Body).Decode(&document)
7980
if err != nil {
80-
return err
81+
return nil, err
8182
}
8283

8384
// Save the uri we used to retrieve this document.
8485
document.Uri = uri
8586

86-
return nil
87+
return &document, nil
8788
}
8889

8990
// Search looks at the document for the specified search term.
90-
func Search(document Document, searchTerm string) ([]SearchResult, error) {
91+
func Search(document *Document, searchTerm string) ([]SearchResult, error) {
9192
var searchResults []SearchResult
9293

9394
for _, item := range document.Channel.Item {

0 commit comments

Comments
 (0)