From ee5bf1d50b9165729d0c61f7d1f968949e3e0638 Mon Sep 17 00:00:00 2001 From: Adam Mathes Date: Wed, 4 Jul 2018 14:58:43 -0700 Subject: enable feed export from web interface --- exporter/exporter.go | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) (limited to 'exporter') diff --git a/exporter/exporter.go b/exporter/exporter.go index 04ced0b..013377d 100644 --- a/exporter/exporter.go +++ b/exporter/exporter.go @@ -2,37 +2,38 @@ package exporter import ( "adammathes.com/neko/models/feed" + "bytes" "encoding/json" "encoding/xml" "fmt" "html/template" - "os" ) -func ExportFeeds(format string) { +func ExportFeeds(format string) string { feeds, err := feed.All() if err != nil { panic(err) } + s := "" switch format { case "text": for _, f := range feeds { - fmt.Printf("%s\n", f.Url) + s = s + fmt.Sprintf("%s\n", f.Url) } case "opml": - fmt.Printf(`neko feeds`) - fmt.Printf("\n") + s = s + fmt.Sprintf(`neko feeds`) + s = s + fmt.Sprintf("\n") for _, f := range feeds { b, _ := xml.Marshal(f) - fmt.Printf("%s\n", string(b)) + s = s + fmt.Sprintf("%s\n", string(b)) } - fmt.Printf(``) + s = s + fmt.Sprintf(``) case "json": js, _ := json.Marshal(feeds) - fmt.Printf("%s\n", js) + s = fmt.Sprintf("%s\n", js) case "html": htmlTemplateString := ` @@ -48,10 +49,14 @@ func ExportFeeds(format string) { ` + var bts bytes.Buffer htmlTemplate, err := template.New("feeds").Parse(htmlTemplateString) - err = htmlTemplate.Execute(os.Stdout, feeds) + err = htmlTemplate.Execute(&bts, feeds) if err != nil { panic(err) } + s = bts.String() } + + return s } -- cgit v1.2.3