---
db/db.go | 17 ++++++++++-------
1 file changed, 10 insertions(+), 7 deletions(-)
diff --git a/db/db.go b/db/db.go
index eed6ac5..3872e03 100644
--- a/db/db.go
+++ b/db/db.go
@@ -130,6 +130,11 @@ func ReadDB(path string) (*Storage, error) {
// CreateFeed will collect the rss feed and process through the elements
// and add the relevant data elements to the database
func (s *Storage) CreateFeed(url string) error {
+ _, ok := s.Feeds[url]
+ if ok {
+ return fmt.Errorf("already subscribed to feed: %s", url)
+ }
+
f, err := parseFeed(url)
if err != nil {
return fmt.Errorf("unable to fetch url: %s", err.Error())
@@ -245,18 +250,16 @@ func (s *Storage) DeleteFeed(url string) error {
return fmt.Errorf("url was empty, unable to delete")
}
+ feed, ok := s.Feeds[url]
+ if !ok {
+ return fmt.Errorf("feed does not exist")
+ }
+
db, err := openDB(s.Path)
if err != nil {
return fmt.Errorf("unable to open db: %s", err.Error())
}
- feed, ok := s.Feeds[url]
- if !ok {
- if err := db.Close(); err != nil {
- return err
- }
- return fmt.Errorf("feed does not exist")
- }
items := feed.Items
for _, key := range items {
// Delete from item database
--
2.27.0