fetcher refact
This commit is contained in:
@@ -15,9 +15,25 @@ type Entry struct {
|
||||
|
||||
// Fetcher is the interface for a fetcher.
|
||||
type Fetcher interface {
|
||||
Name() string
|
||||
Fetch() []Entry
|
||||
}
|
||||
|
||||
// BaseFetcher contains common fields for all fetchers.
|
||||
type BaseFetcher struct {
|
||||
BaseURL string
|
||||
Token string
|
||||
Cache *Cache
|
||||
}
|
||||
|
||||
// TryCreateEntry checks the cache and creates an Entry if the value has changed.
|
||||
func (b *BaseFetcher) TryCreateEntry(cacheKey, cacheValue, title, url string) *Entry {
|
||||
if b.Cache.TryUpdate(cacheKey, cacheValue) {
|
||||
return &Entry{Title: title, URL: url}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// FetcherRequest represents a common HTTP request configuration.
|
||||
type FetcherRequest struct {
|
||||
BaseURL string
|
||||
|
||||
Reference in New Issue
Block a user