summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authornytpu <alex@nytpu.com>2021-03-18 11:36:57 -0600
committernytpu <alex@nytpu.com>2021-03-18 11:36:57 -0600
commit6cf5ca01cf4123b66c75471ce61f93213badf820 (patch)
tree7f83175d543d47bebc29abc14d5dcfed54921e67 /core
parent00de991f6bc39c0f46d5124bddedd4e309829817 (diff)
Changed url.URL to string so the json is less bloated
Diffstat (limited to 'core')
-rw-r--r--core/core.go5
-rw-r--r--core/structs.go25
2 files changed, 16 insertions, 14 deletions
diff --git a/core/core.go b/core/core.go
index 1f92d76..a97b8e3 100644
--- a/core/core.go
+++ b/core/core.go
@@ -16,7 +16,6 @@ import (
"encoding/json"
"fmt"
"io/ioutil"
- "net/url"
"os"
"path/filepath"
"sync"
@@ -55,10 +54,10 @@ func Init(dataPath string) error {
}
if Data.Feeds == nil {
- Data.Feeds = make(map[url.URL]*Feed)
+ Data.Feeds = make(map[string]*Feed)
}
if Data.Pages == nil {
- Data.Pages = make(map[url.URL]*Page)
+ Data.Pages = make(map[string]*Page)
}
return nil
}
diff --git a/core/structs.go b/core/structs.go
index 7e4dc09..6270de8 100644
--- a/core/structs.go
+++ b/core/structs.go
@@ -22,8 +22,8 @@ import (
// FullData is used for both reading from json and for storing the global feeds
// map. contains read mutexes so concurrency can be used.
type FullData struct {
- Feeds map[url.URL]*Feed `json:"feeds,omitempty"`
- Pages map[url.URL]*Page `json:"pages,omitempty"`
+ Feeds map[string]*Feed `json:"feeds,omitempty"`
+ Pages map[string]*Page `json:"pages,omitempty"`
FeedsMu *sync.RWMutex
PagesMu *sync.RWMutex
@@ -32,8 +32,8 @@ type FullData struct {
// Feed holds all the necessary fields when storing a feed
type Feed struct {
Title string `json:"title,omitempty"`
- Link *url.URL `json:"link,omitempty"` // link to the human-readable page for the feed. same as FeedLink for gemini feeds.
- FeedLink *url.URL `json:"feedlink,omitempty"` // link to the feed itself.
+ Link string `json:"link,omitempty"` // link to the human-readable page for the feed. same as FeedLink for gemini feeds.
+ FeedLink string `json:"feedlink,omitempty"` // link to the feed itself.
Updated time.Time `json:"updated,omitempty"`
Items []*Item `json:"items,omitempty"`
}
@@ -42,7 +42,7 @@ type Feed struct {
type Item struct {
Title string `json:"title,omitempty"` // if empty, use Link as title
Content string `json:"content,omitempty"`
- Link *url.URL `json:"link,omitempty"`
+ Link string `json:"link,omitempty"`
Published time.Time `json:"updated,omitempty"`
}
@@ -50,7 +50,7 @@ type Item struct {
// changes.
type Page struct {
Title string `json:"title,omitempty"`
- Link *url.URL `json:"link,omitempty"`
+ Link string `json:"link,omitempty"`
Updated time.Time `json:"updated,omitempty"`
Hash string `json:"hash,omitempty"`
}
@@ -74,6 +74,8 @@ func GofeedConvert(f *gofeed.Feed, title string) (*Feed, error) {
if err != nil {
return nil, err
}
+ new.Link = f.Link
+ new.FeedLink = f.FeedLink
for _, v := range f.Items {
item := &Item{}
@@ -84,6 +86,7 @@ func GofeedConvert(f *gofeed.Feed, title string) (*Feed, error) {
if err != nil {
return nil, err
}
+ item.Link = f.FeedLink
new.Items = append(new.Items, item)
}
@@ -94,10 +97,10 @@ func GofeedConvert(f *gofeed.Feed, title string) (*Feed, error) {
// InsertFeed will insert or update a core.Feed in a core.FullData
func (d *FullData) InsertFeed(new *Feed, remote *url.URL) {
d.FeedsMu.Lock()
- oldFeed, ok := d.Feeds[*remote]
+ oldFeed, ok := d.Feeds[remote.String()]
if !ok || !reflect.DeepEqual(new, oldFeed) {
// Feeds are different, or there was never an old one
- d.Feeds[*remote] = new
+ d.Feeds[remote.String()] = new
d.FeedsMu.Unlock()
} else {
d.FeedsMu.Unlock()
@@ -107,10 +110,10 @@ func (d *FullData) InsertFeed(new *Feed, remote *url.URL) {
// InsertPage will insert or update a core.Page in a core.FullData
func (d *FullData) InsertPage(new *Page, remote *url.URL) {
d.PagesMu.Lock()
- _, ok := d.Pages[*remote]
- if !ok || d.Pages[*remote].Hash != new.Hash {
+ _, ok := d.Pages[remote.String()]
+ if !ok || d.Pages[remote.String()].Hash != new.Hash {
// pages are different, or there was never an old one
- d.Pages[*remote] = new
+ d.Pages[remote.String()] = new
d.PagesMu.Unlock()
} else {
d.PagesMu.Unlock()