fetcher refact

This commit is contained in:
Zsolt Tasnadi
2026-01-20 08:39:02 +01:00
parent 6be44be9bf
commit 4f168197b8
5 changed files with 113 additions and 79 deletions

View File

@@ -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