RetrieveFeeds reads and unmarshals the feed data file.
()
| 16 | |
| 17 | // RetrieveFeeds reads and unmarshals the feed data file. |
| 18 | func RetrieveFeeds() ([]*Feed, error) { |
| 19 | // Open the file. |
| 20 | file, err := os.Open(dataFile) |
| 21 | if err != nil { |
| 22 | return nil, err |
| 23 | } |
| 24 | |
| 25 | // Schedule the file to be closed once |
| 26 | // the function returns. |
| 27 | defer file.Close() |
| 28 | |
| 29 | // Decode the file into a slice of pointers |
| 30 | // to Feed values. |
| 31 | var feeds []*Feed |
| 32 | err = json.NewDecoder(file).Decode(&feeds) |
| 33 | |
| 34 | // We don't need to check for errors, the caller can do this. |
| 35 | return feeds, err |
| 36 | } |