summaryrefslogtreecommitdiff
path: root/gemini
diff options
context:
space:
mode:
Diffstat (limited to 'gemini')
-rw-r--r--gemini/gemtext/sub.go16
-rw-r--r--gemini/gemtext/sub_test.go7
2 files changed, 16 insertions, 7 deletions
diff --git a/gemini/gemtext/sub.go b/gemini/gemtext/sub.go
index 1247643..365d41b 100644
--- a/gemini/gemtext/sub.go
+++ b/gemini/gemtext/sub.go
@@ -3,6 +3,7 @@ package gemtext
import (
"bytes"
"html/template"
+ "io"
"net/url"
"regexp"
"strconv"
@@ -14,12 +15,17 @@ import (
//
// It identifies feed fields and entries according to the specification at
// gemini://gemini.circumlunar.space/docs/companion/subscription.gmi
-func GmisubToAtom(doc Document, location url.URL) string {
- buf := &bytes.Buffer{}
- if err := atomTmpl.Execute(buf, parseGemSub(doc, &location)); err != nil {
- panic(err)
+func GmisubToAtom(doc Document, location url.URL, out io.Writer) error {
+ if _, err := out.Write([]byte(`<?xml version="1.0" encoding="utf-8"?>`)); err != nil {
+ return err
}
- return `<?xml version="1.0" encoding="utf-8"?>` + "\n" + buf.String()
+ if _, err := out.Write([]byte{'\n'}); err != nil {
+ return err
+ }
+ if err := atomTmpl.Execute(out, parseGemSub(doc, &location)); err != nil {
+ return err
+ }
+ return nil
}
type gmiSub struct {
diff --git a/gemini/gemtext/sub_test.go b/gemini/gemtext/sub_test.go
index 26f98ed..f080705 100644
--- a/gemini/gemtext/sub_test.go
+++ b/gemini/gemtext/sub_test.go
@@ -51,8 +51,11 @@ func TestGemsubToAtom(t *testing.T) {
if err != nil {
t.Fatal(err)
}
- xml := GmisubToAtom(doc, *loc)
- if xml != test.output {
+ out := &bytes.Buffer{}
+ if err := GmisubToAtom(doc, *loc, out); err != nil {
+ t.Fatal(err)
+ }
+ if out.String() != test.output {
t.Fatal("mismatched output")
}
})