aboutsummaryrefslogtreecommitdiff
path: root/internal/feed
diff options
context:
space:
mode:
authorRené 'Necoro' Neumann <necoro@necoro.eu>2021-02-27 21:22:38 +0100
committerRené 'Necoro' Neumann <necoro@necoro.eu>2021-02-27 21:22:38 +0100
commitae96e1bd2516ff2c70ad9dc010da84b7a03b9a35 (patch)
tree319e04d268ca1c881205c89da45ad0c1f161bd23 /internal/feed
parentcf3e619639a9e1fd182e0c2437a0619e3ee2ab7f (diff)
downloadfeed2imap-go-ae96e1bd2516ff2c70ad9dc010da84b7a03b9a35.tar.gz
feed2imap-go-ae96e1bd2516ff2c70ad9dc010da84b7a03b9a35.tar.bz2
feed2imap-go-ae96e1bd2516ff2c70ad9dc010da84b7a03b9a35.zip
Put storing / loading details into cache implementation
Diffstat (limited to 'internal/feed')
-rw-r--r--internal/feed/cache/cache.go10
-rw-r--r--internal/feed/cache/v1.go12
2 files changed, 17 insertions, 5 deletions
diff --git a/internal/feed/cache/cache.go b/internal/feed/cache/cache.go
index 3a80df1..9613f06 100644
--- a/internal/feed/cache/cache.go
+++ b/internal/feed/cache/cache.go
@@ -2,9 +2,9 @@ package cache
import (
"bufio"
- "encoding/gob"
"errors"
"fmt"
+ "io"
"os"
"path/filepath"
"time"
@@ -24,6 +24,8 @@ const (
type Impl interface {
cachedFeed(*feed.Feed) CachedFeed
transformTo(Version) (Impl, error)
+ load(io.Reader) error
+ store(io.Writer) error
Version() Version
Info() string
SpecificInfo(interface{}) string
@@ -103,8 +105,7 @@ func (cache *Cache) store(fileName string) error {
return fmt.Errorf("writing to '%s': %w", fileName, err)
}
- encoder := gob.NewEncoder(writer)
- if err = encoder.Encode(cache.Impl); err != nil {
+ if err = cache.Impl.store(writer); err != nil {
return fmt.Errorf("encoding cache: %w", err)
}
@@ -164,8 +165,7 @@ func Load(fileName string) (Cache, error) {
return Cache{}, err
}
- decoder := gob.NewDecoder(reader)
- if err = decoder.Decode(cache); err != nil {
+ if err = cache.load(reader); err != nil {
return Cache{}, fmt.Errorf("decoding for version '%d' from '%s': %w", version, fileName, err)
}
diff --git a/internal/feed/cache/v1.go b/internal/feed/cache/v1.go
index 7d95d4c..17a0346 100644
--- a/internal/feed/cache/v1.go
+++ b/internal/feed/cache/v1.go
@@ -3,8 +3,10 @@ package cache
import (
"crypto/sha256"
"encoding/base64"
+ "encoding/gob"
"encoding/hex"
"fmt"
+ "io"
"sort"
"strconv"
"strings"
@@ -373,3 +375,13 @@ func filterItems(items []cachedItem) []cachedItem {
return copiedItems
}
+
+func (cache *v1Cache) load(reader io.Reader) error {
+ decoder := gob.NewDecoder(reader)
+ return decoder.Decode(cache)
+}
+
+func (cache *v1Cache) store(writer io.Writer) error {
+ encoder := gob.NewEncoder(writer)
+ return encoder.Encode(cache)
+}