From 77982cb60eaee33593446be6985c2aaa771ce0a9 Mon Sep 17 00:00:00 2001 From: nytpu Date: Thu, 18 Mar 2021 15:01:25 -0600 Subject: [PATCH] add Export function to core.FullData --- core/core.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/core/core.go b/core/core.go index 513c84c..6b68f3f 100644 --- a/core/core.go +++ b/core/core.go @@ -15,6 +15,7 @@ package core import ( "encoding/json" "fmt" + "io" "io/ioutil" "os" "path/filepath" @@ -81,3 +82,23 @@ func (d *FullData) WriteJSON(dataPath string) error { err = os.Rename(path, filepath.Join(dataPath, "comitium.json")) return err } + +func (d *FullData) Export(w io.Writer) { + fmt.Fprint(w, "# comitium subscribed feeds\n## Feeds\n\n") + d.FeedsMu.RLock() + for _, v := range d.Feeds { + fmt.Fprintf(w, "=> %v %v\n", v.FeedLink, v.Title) + } + d.FeedsMu.RUnlock() + + fmt.Fprint(w, "\n\n## Pages\n\n") + d.PagesMu.RLock() + for _, v := range d.Pages { + fmt.Fprintf(w, "=> %v", v.Link) + if v.Title != "" { + fmt.Fprintf(w, " %v", v.Title) + } + fmt.Fprint(w, "\n") + } + d.PagesMu.RUnlock() +}