Skip to content

Commit 6b37e73

Browse files
Saving Changes
1 parent 39033e4 commit 6b37e73

3 files changed

Lines changed: 11 additions & 11 deletions

File tree

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

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package data
22

33
import (
44
"encoding/json"
5-
"io/ioutil"
65
"os"
76
)
87

@@ -21,21 +20,17 @@ type (
2120

2221
// Load retrieves and unmarshals the data for the program.
2322
func Load() ([]Feed, error) {
24-
// Get the current directory we are running inside.
25-
pwd, err := os.Getwd()
26-
if err != nil {
27-
return nil, err
28-
}
29-
3023
// Read the entire file.
31-
data, err := ioutil.ReadFile(pwd + "/" + dataFile)
24+
file, err := os.Open(dataFile)
3225
if err != nil {
3326
return nil, err
3427
}
3528

29+
defer file.Close()
30+
3631
// Unmarshal the json document into a slice of feeds.
3732
var feeds []Feed
38-
err = json.Unmarshal(data, &feeds)
33+
err = json.NewDecoder(file).Decode(&feeds)
3934
if err != nil {
4035
return nil, err
4136
}

‎src/chapter2/search/main.go‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,18 @@ package main
22

33
import (
44
"log"
5+
"os"
56
"sync"
67

78
"github.com/goinaction/code/src/chapter2/search/data"
89
search "github.com/goinaction/code/src/chapter2/search/feed"
910
"github.com/goinaction/code/src/chapter2/search/rss"
1011
)
1112

13+
func init() {
14+
log.SetOutput(os.Stdout)
15+
}
16+
1217
// NewMatcher is a factory that creates matcher values based
1318
// on the type of feed specified.
1419
func NewMatcher(feed data.Feed) search.Matcher {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ type (
2626
// image defines the fields associated with the image tag in the rss document.
2727
image struct {
2828
XMLName xml.Name `xml:"image"`
29-
Url string `xml:"url"`
29+
URL string `xml:"url"`
3030
Title string `xml:"title"`
3131
Link string `xml:"link"`
3232
}
@@ -116,7 +116,7 @@ func (m *matcher) Match(searchTerm string) ([]feed.Result, error) {
116116
// retrieve performs a HTTP Get request for the rss feed and unmarshals the results.
117117
func (m *matcher) retrieve() (*document, error) {
118118
if m.Feed.Uri == "" {
119-
return nil, errors.New("No RSS Feed Uri Provided")
119+
return nil, errors.New("No rss feed uri provided")
120120
}
121121

122122
// Retrieve the rss feed document from the web.

0 commit comments

Comments
 (0)