Skip to content

Commit 6f3fcd3

Browse files
Fix return arguments
1 parent 81498a7 commit 6f3fcd3

2 files changed

Lines changed: 8 additions & 8 deletions

File tree

‎src/chapter2/search/feeds/feed.go‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,25 @@ type (
1919
)
2020

2121
// Load retrieves and unmarshals the data for the program.
22-
func Load(sites *[]Site) error {
22+
func Load() ([]Site, error) {
2323
// Get the current directory we are running inside.
2424
pwd, err := os.Getwd()
2525
if err != nil {
26-
return err
26+
return nil, err
2727
}
2828

2929
// Read the entire file.
3030
data, err := ioutil.ReadFile(pwd + "/" + dataFile)
3131
if err != nil {
32-
return err
32+
return nil, err
3333
}
3434

3535
// Unmarshal the json document into a slice of sites.
36-
err = json.Unmarshal(data, sites)
36+
var sites []Site
37+
err = json.Unmarshal(data, &sites)
3738
if err != nil {
38-
return err
39+
return nil, err
3940
}
4041

41-
return nil
42+
return sites, nil
4243
}

‎src/chapter2/search/main.go‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ func main() {
1313
searchTerm := "president"
1414

1515
// Load the feeds for the data file.
16-
var sites []feeds.Site
17-
err := feeds.Load(&sites)
16+
sites, err := feeds.Load()
1817
if err != nil {
1918
log.Fatal(err)
2019
}

0 commit comments

Comments
 (0)