From cb8185e5bbaef10236e7a7aa3b8e7ad597f435b6 Mon Sep 17 00:00:00 2001 From: Giovanni Harting <539@idlegandalf.com> Date: Wed, 7 Dec 2022 15:39:17 +0100 Subject: [PATCH] use buffer to deliver sitemap --- main.go | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/main.go b/main.go index a77732f..f487a86 100644 --- a/main.go +++ b/main.go @@ -29,7 +29,6 @@ import ( "golang.org/x/text/language" "golang.org/x/time/rate" "gopkg.in/yaml.v3" - "io" "net" "net/http" "os" @@ -1092,16 +1091,13 @@ func getSiteMap(c *gin.Context) { } } - tReader, tWriter := io.Pipe() - + readBuf := new(bytes.Buffer) sm.Finalize() - go func() { - _, err = sm.WriteTo(tWriter) - if err != nil { - log.Warningf("error writing to pipe: %v", err) - } - }() - c.DataFromReader(http.StatusOK, -1, "application/xml", tReader, nil) + _, err = sm.WriteTo(readBuf) + if err != nil { + log.Warningf("error writing to pipe: %v", err) + } + c.DataFromReader(http.StatusOK, int64(readBuf.Len()), "application/xml", readBuf, nil) } /*