diff options
author | René 'Necoro' Neumann <necoro@necoro.eu> | 2020-06-20 22:37:44 +0200 |
---|---|---|
committer | René 'Necoro' Neumann <necoro@necoro.eu> | 2020-06-20 22:37:44 +0200 |
commit | eefdc799b929a4d6407737d281c34dd940e2823f (patch) | |
tree | 8cf6b1842dc5ca6a5044c1b3caba0916b8328eca /internal/feed/cache_v1.go | |
parent | 92f8d785ea478c02efd32f03478bcd11c85b40a4 (diff) | |
download | feed2imap-go-eefdc799b929a4d6407737d281c34dd940e2823f.tar.gz feed2imap-go-eefdc799b929a4d6407737d281c34dd940e2823f.tar.bz2 feed2imap-go-eefdc799b929a4d6407737d281c34dd940e2823f.zip |
print-cache: Tool for printing the contents of the cache
Diffstat (limited to '')
-rw-r--r-- | internal/feed/cache_v1.go | 51 |
1 files changed, 50 insertions, 1 deletions
diff --git a/internal/feed/cache_v1.go b/internal/feed/cache_v1.go index 02890e1..b5d6b3e 100644 --- a/internal/feed/cache_v1.go +++ b/internal/feed/cache_v1.go @@ -6,6 +6,7 @@ import ( "encoding/hex" "fmt" "strconv" + "strings" "time" "github.com/google/uuid" @@ -25,6 +26,11 @@ func (id feedId) String() string { return strconv.FormatUint(uint64(id), 16) } +func idFromString(s string) feedId { + id, _ := strconv.ParseUint(s, 16, 64) + return feedId(id) +} + type v1Cache struct { Ids map[feedDescriptor]feedId NextId uint64 @@ -58,12 +64,15 @@ type cachedItem struct { func (item cachedItem) String() string { return fmt.Sprintf(`{ + ID: %s Title: %q Guid: %q Link: %q Date: %s Hash: %s -}`, item.Title, item.Guid, item.Link, util.TimeFormat(item.Date), item.Hash) +}`, + base64.RawURLEncoding.EncodeToString(item.ID[:]), + item.Title, item.Guid, item.Link, util.TimeFormat(item.Date), item.Hash) } func (cf *cachedFeed) Checked(withFailure bool) { @@ -97,6 +106,46 @@ func (cache *v1Cache) Version() Version { return v1Version } +func (cache *v1Cache) Info() string { + b := strings.Builder{} + for descr, id := range cache.Ids { + b.WriteString(fmt.Sprintf("%3s: %s (%s)\n", id.String(), descr.Name, descr.Url)) + } + return b.String() +} + +func (cache *v1Cache) SpecificInfo(i interface{}) string { + id := idFromString(i.(string)) + + b := strings.Builder{} + feed := cache.Feeds[id] + + for descr, fId := range cache.Ids { + if id == fId { + b.WriteString(descr.Name) + b.WriteString(" -- ") + b.WriteString(descr.Url) + b.WriteByte('\n') + break + } + } + + b.WriteString(fmt.Sprintf(` +Last Check: %s +Num Failures: %d +Num Items: %d +`, + util.TimeFormat(feed.LastCheck), + feed.NumFailures, + len(feed.Items))) + + for _, item := range feed.Items { + b.WriteString("\n--------------------\n") + b.WriteString(item.String()) + } + return b.String() +} + func newV1Cache() *v1Cache { cache := v1Cache{ Ids: map[feedDescriptor]feedId{}, |