use buffer to deliver sitemap

This commit is contained in:
2022-12-07 15:39:17 +01:00
parent ba1a1cf31f
commit cb8185e5bb

16
main.go
View File

@@ -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)
}
/*