write directly to the writer, don't pass through Sprintf

This commit is contained in:
David 2020-09-12 16:49:54 -04:00
parent 352ec35890
commit cb3282304b
1 changed files with 5 additions and 3 deletions

View File

@ -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
}