From b0a78c4a1e2b0ca3276ab2578f0fc5150ce70ae5 Mon Sep 17 00:00:00 2001 From: James Tombleson Date: Sat, 10 Dec 2022 11:13:45 -0800 Subject: [PATCH] updated to models --- services/cache/cache.go | 12 ++++++------ services/cache/common.go | 4 ++-- services/cache/monitor.go | 6 +++--- services/input/reddit.go | 18 +++++++++--------- services/input/rss.go | 6 +++--- services/input/rss_test.go | 4 ++-- 6 files changed, 25 insertions(+), 25 deletions(-) diff --git a/services/cache/cache.go b/services/cache/cache.go index 8c0b22d..eddefdf 100644 --- a/services/cache/cache.go +++ b/services/cache/cache.go @@ -3,7 +3,7 @@ package cache import ( "time" - "github.com/jtom38/newsbot/collector/domain/model" + "github.com/jtom38/newsbot/collector/domain/models" ) type CacheClient struct { @@ -19,7 +19,7 @@ func NewCacheClient(group string) CacheClient { } func (cc *CacheClient) Insert(key string, value string) { - item := model.CacheItem{ + item := models.CacheItem{ Key: key, Value: value, Group: cc.group, @@ -29,7 +29,7 @@ func (cc *CacheClient) Insert(key string, value string) { cacheStorage = append(cacheStorage, &item) } -func (cc *CacheClient) FindByKey(key string) (*model.CacheItem, error) { +func (cc *CacheClient) FindByKey(key string) (*models.CacheItem, error) { for _, item := range cacheStorage { if item.Group != cc.group { continue @@ -46,10 +46,10 @@ func (cc *CacheClient) FindByKey(key string) (*model.CacheItem, error) { return item, nil } - return &model.CacheItem{}, ErrCacheRecordMissing + return &models.CacheItem{}, ErrCacheRecordMissing } -func (cc *CacheClient) FindByValue(value string) (*model.CacheItem, error) { +func (cc *CacheClient) FindByValue(value string) (*models.CacheItem, error) { for _, item := range cacheStorage { if item.Group != cc.group { continue @@ -65,5 +65,5 @@ func (cc *CacheClient) FindByValue(value string) (*model.CacheItem, error) { } return item, nil } - return &model.CacheItem{}, ErrCacheRecordMissing + return &models.CacheItem{}, ErrCacheRecordMissing } diff --git a/services/cache/common.go b/services/cache/common.go index 0be3815..b53d5fe 100644 --- a/services/cache/common.go +++ b/services/cache/common.go @@ -3,11 +3,11 @@ package cache import ( "errors" - "github.com/jtom38/newsbot/collector/domain/model" + "github.com/jtom38/newsbot/collector/domain/models" ) var ( - cacheStorage []*model.CacheItem + cacheStorage []*models.CacheItem ErrCacheRecordMissing = errors.New("unable to find the requested record") ) diff --git a/services/cache/monitor.go b/services/cache/monitor.go index 450a3ee..e6481f2 100644 --- a/services/cache/monitor.go +++ b/services/cache/monitor.go @@ -3,7 +3,7 @@ package cache import ( "time" - "github.com/jtom38/newsbot/collector/domain/model" + "github.com/jtom38/newsbot/collector/domain/models" ) // When a record becomes tainted, it needs to be renewed or it will be dropped from the cache. @@ -36,8 +36,8 @@ func (cam CacheAgeMonitor) CheckExpiredEntries() { } // This creates a new slice and skips over the item that needs to be dropped -func (cam CacheAgeMonitor) removeEntry(index int) []*model.CacheItem { - var temp []*model.CacheItem +func (cam CacheAgeMonitor) removeEntry(index int) []*models.CacheItem { + var temp []*models.CacheItem for i, item := range cacheStorage { if i != index { temp = append(temp, item) diff --git a/services/input/reddit.go b/services/input/reddit.go index cd68313..145c978 100644 --- a/services/input/reddit.go +++ b/services/input/reddit.go @@ -12,7 +12,7 @@ import ( "github.com/go-rod/rod" "github.com/go-rod/rod/lib/launcher" "github.com/jtom38/newsbot/collector/database" - "github.com/jtom38/newsbot/collector/domain/model" + "github.com/jtom38/newsbot/collector/domain/models" "github.com/jtom38/newsbot/collector/services/config" ) @@ -65,8 +65,8 @@ func (rc *RedditClient) GetPage(parser *rod.Browser, url string) *rod.Page { // GetContent() reaches out to Reddit and pulls the Json data. // It will then convert the data to a struct and return the struct. -func (rc *RedditClient) GetContent() (model.RedditJsonContent, error) { - var items model.RedditJsonContent = model.RedditJsonContent{} +func (rc *RedditClient) GetContent() (models.RedditJsonContent, error) { + var items models.RedditJsonContent = models.RedditJsonContent{} // TODO Wire this to support the config options Url := fmt.Sprintf("%v.json", rc.record.Url) @@ -88,7 +88,7 @@ func (rc *RedditClient) GetContent() (model.RedditJsonContent, error) { return items, nil } -func (rc *RedditClient) ConvertToArticles(items model.RedditJsonContent) []database.Article { +func (rc *RedditClient) ConvertToArticles(items models.RedditJsonContent) []database.Article { var redditArticles []database.Article for _, item := range items.Data.Children { var article database.Article @@ -104,7 +104,7 @@ func (rc *RedditClient) ConvertToArticles(items model.RedditJsonContent) []datab // ConvertToArticle() will take the reddit model struct and convert them over to Article structs. // This data can be passed to the database. -func (rc *RedditClient) convertToArticle(source model.RedditPost) (database.Article, error) { +func (rc *RedditClient) convertToArticle(source models.RedditPost) (database.Article, error) { var item database.Article if source.Content == "" && source.Url != "" { @@ -131,7 +131,7 @@ func (rc *RedditClient) convertToArticle(source model.RedditPost) (database.Arti return item, nil } -func (rc *RedditClient) convertPicturePost(source model.RedditPost) database.Article { +func (rc *RedditClient) convertPicturePost(source models.RedditPost) database.Article { var item = database.Article{ Sourceid: rc.record.ID, Title: source.Title, @@ -149,7 +149,7 @@ func (rc *RedditClient) convertPicturePost(source model.RedditPost) database.Art return item } -func (rc *RedditClient) convertTextPost(source model.RedditPost) database.Article { +func (rc *RedditClient) convertTextPost(source models.RedditPost) database.Article { var item = database.Article{ Sourceid: rc.record.ID, Tags: "a", @@ -164,7 +164,7 @@ func (rc *RedditClient) convertTextPost(source model.RedditPost) database.Articl return item } -func (rc *RedditClient) convertVideoPost(source model.RedditPost) database.Article { +func (rc *RedditClient) convertVideoPost(source models.RedditPost) database.Article { var item = database.Article{ Sourceid: rc.record.ID, Tags: "a", @@ -180,7 +180,7 @@ func (rc *RedditClient) convertVideoPost(source model.RedditPost) database.Artic } // This post is nothing more then a redirect to another location. -func (rc *RedditClient) convertRedirectPost(source model.RedditPost) database.Article { +func (rc *RedditClient) convertRedirectPost(source models.RedditPost) database.Article { var item = database.Article{ Sourceid: rc.record.ID, Tags: "a", diff --git a/services/input/rss.go b/services/input/rss.go index e71c979..7d46f22 100644 --- a/services/input/rss.go +++ b/services/input/rss.go @@ -4,16 +4,16 @@ import ( "fmt" "log" - "github.com/jtom38/newsbot/collector/domain/model" + "github.com/jtom38/newsbot/collector/domain/models" "github.com/jtom38/newsbot/collector/services/cache" "github.com/mmcdole/gofeed" ) type rssClient struct { - SourceRecord model.Sources + SourceRecord models.Sources } -func NewRssClient(sourceRecord model.Sources) rssClient { +func NewRssClient(sourceRecord models.Sources) rssClient { client := rssClient{ SourceRecord: sourceRecord, } diff --git a/services/input/rss_test.go b/services/input/rss_test.go index de6ded5..05c0731 100644 --- a/services/input/rss_test.go +++ b/services/input/rss_test.go @@ -3,11 +3,11 @@ package input_test import ( "testing" - "github.com/jtom38/newsbot/collector/domain/model" + "github.com/jtom38/newsbot/collector/domain/models" "github.com/jtom38/newsbot/collector/services/input" ) -var rssRecord = model.Sources{ +var rssRecord = models.Sources{ ID: 1, Name: "ArsTechnica", Url: "https://feeds.arstechnica.com/arstechnica/index",