From cb3282304b4bbbfa8d4efb19e10cb2646dcfa148 Mon Sep 17 00:00:00 2001 From: David Ashby Date: Sat, 12 Sep 2020 16:49:54 -0400 Subject: [PATCH] write directly to the writer, don't pass through Sprintf --- main.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/main.go b/main.go index 6e0cab4..4b6ccb6 100644 --- a/main.go +++ b/main.go @@ -74,7 +74,7 @@ func (w *response) WriteStatus(code int, meta string) (int, error) { w.status = code w.meta = meta w.statusSent = true - return w.connection.Write([]byte(fmt.Sprintf("%d %s\r\n", code, meta))) + return fmt.Fprintf(w.connection, "%d %s\r\n", code, meta) } func (w *response) Write(b []byte) (int, error) { @@ -110,9 +110,11 @@ func genIndex(folder, rel string) ([]byte, error) { if err != nil { return []byte{}, err } - ret := bytes.NewBuffer([]byte(fmt.Sprintf("# %s\r\n\r\n", rel))) + ret := bytes.NewBuffer([]byte{}) + + fmt.Fprintf(ret, "# %s\r\n\r\n", rel) for _, file := range files { - ret.Write([]byte(fmt.Sprintf("=> %s %s\r\n", filepath.Join(rel, file.Name()), file.Name()))) + fmt.Fprintf(ret, "=> %s %s\r\n", filepath.Join(rel, file.Name()), file.Name()) } return ret.Bytes(), nil }