James Tombleson
eba63c27ef
* added extra packages to help with parsing * getting the core built for Youtube collection. The feed can be pulled and starting to build the article object * added some tests, reddit will need more love but youtube is starting off with more tests. Starting to add Rod to pull missing values from the site * Added rod to work with browser automation * Moved the config inside the client as they can change within runtime and need to be refreshed on each client creation * added more features to collect data per video and tests to support them. * adding the cache and tests * moved errors to var values at the top * youtube is now getting collected and tests have been setup * resolved an issue with the config * setting up the first interface, its not used yet * more updates to the cache service. Not finished yet and could see rework * added logic to monitor Youtube. Still basic logic that needs to be wired up to the database
40 lines
764 B
Go
40 lines
764 B
Go
package services
|
|
|
|
import (
|
|
"errors"
|
|
|
|
"github.com/jtom38/newsbot/collector/domain/model"
|
|
)
|
|
|
|
type CacheClient struct{}
|
|
|
|
var (
|
|
cacheStorage []*model.CacheItem
|
|
|
|
ErrCacheRecordMissing = errors.New("unable to find the requested record.")
|
|
)
|
|
|
|
|
|
func NewCacheClient() CacheClient {
|
|
return CacheClient{}
|
|
}
|
|
|
|
func (cc *CacheClient) Insert(item *model.CacheItem) {
|
|
//_, err := cc.Find(item.Key, item.Group)
|
|
//if err != nil { }
|
|
cacheStorage = append(cacheStorage, item)
|
|
}
|
|
|
|
func (cc *CacheClient) Find(key string, group string) (*model.CacheItem, error) {
|
|
//go cc.FindExpiredEntries()
|
|
|
|
for _, item := range cacheStorage {
|
|
if item.Group != group { continue }
|
|
|
|
if item.Key != key { continue }
|
|
|
|
return item, nil
|
|
}
|
|
|
|
return &model.CacheItem{}, ErrCacheRecordMissing
|
|
} |