Load *ArticleList, *Taglist and *Channel correctly

This commit is contained in:
Jason Streifling 2024-03-06 15:37:42 +01:00
parent 6baaec5b33
commit f1abb9d353
2 changed files with 15 additions and 7 deletions

View File

@ -140,11 +140,15 @@ func LoadArticleList(filename string) (*ArticleList, error) {
return nil, fmt.Errorf("error opening key file: %v", err) return nil, fmt.Errorf("error opening key file: %v", err)
} }
articleList := NewArticleList() articleList := initArticleList()
if err = gob.NewDecoder(file).Decode(&articleList.articles); err != nil { if err = gob.NewDecoder(file).Decode(&articleList.articles); err != nil {
return nil, fmt.Errorf("error decoding key: %v", err) return nil, fmt.Errorf("error decoding key: %v", err)
} }
articleList.wg.Add(1)
go articleList.start()
articleList.wg.Wait()
return articleList, nil return articleList, nil
} }
@ -189,10 +193,14 @@ func LoadTagList(filename string) (*TagList, error) {
} }
defer file.Close() defer file.Close()
tagList := NewTagList() tagList := initTagList()
if err = gob.NewDecoder(file).Decode(&tagList.tags); err != nil { if err = gob.NewDecoder(file).Decode(&tagList.tags); err != nil {
return nil, fmt.Errorf("error decoding key: %v", err) return nil, fmt.Errorf("error decoding key: %v", err)
} }
tagList.wg.Add(1)
go tagList.start()
tagList.wg.Wait()
return tagList, nil return tagList, nil
} }

View File

@ -70,17 +70,17 @@ func LoadChannel(filename string) (*Channel, error) {
} }
defer file.Close() defer file.Close()
channel := initChannel()
channel.wg.Add(1)
go channel.start()
channel.wg.Wait()
tmpChannel := new(rss.Channel) tmpChannel := new(rss.Channel)
if err = gob.NewDecoder(file).Decode(tmpChannel); err != nil { if err = gob.NewDecoder(file).Decode(tmpChannel); err != nil {
return nil, fmt.Errorf("error decoding channel from file %v: %v", filename, err) return nil, fmt.Errorf("error decoding channel from file %v: %v", filename, err)
} }
channel := initChannel()
channel.wg.Add(1)
go channel.start()
channel.wg.Wait()
channel.Set(*tmpChannel) channel.Set(*tmpChannel)
return channel, nil return channel, nil
} }