package input import ( "fmt" "log" "git.jamestombleson.com/jtom38/newsbot-api/internal/domain" "git.jamestombleson.com/jtom38/newsbot-api/internal/services/cache" "github.com/mmcdole/gofeed" ) type rssClient struct { SourceRecord domain.SourceEntity } func NewRssClient(sourceRecord domain.SourceEntity) rssClient { client := rssClient{ SourceRecord: sourceRecord, } return client } //func (rc rssClient) ReplaceSourceRecord(source model.Sources) { //rc.SourceRecord = source //} func (rc rssClient) getCacheGroup() string { return fmt.Sprintf("rss-%v", rc.SourceRecord.DisplayName) } func (rc rssClient) GetContent() error { feed, err := rc.PullFeed() if err != nil { return err } cacheClient := cache.NewCacheClient(rc.getCacheGroup()) for _, item := range feed.Items { log.Println(item) cacheClient.FindByValue(item.Link) } return nil } func (rc rssClient) PullFeed() (*gofeed.Feed, error) { feedUri := fmt.Sprintf("%v", rc.SourceRecord.Url) fp := gofeed.NewParser() feed, err := fp.ParseURL(feedUri) if err != nil { return nil, err } return feed, nil }