xerogolang icon indicating copy to clipboard operation
xerogolang copied to clipboard

Bug in helpers.ReaderToString(reader io.ReadCloser) string

Open deze333 opened this issue 6 years ago • 0 comments

A small bug in helpers.go that results in:

  • the function must return a string, not print it, as a (unwanted) result errors get printed twice to console
  • (unneeded) call to fmt.Printf(newString) missing format string resulting in %v appended to output

As a workaround I simply commented out unneeded lines:

//ReaderToString converts an io.ReadCloser to a string
func ReaderToString(reader io.ReadCloser) string {
	if reader == nil {
		return ""
	}
	buf := new(bytes.Buffer)
	_, err := buf.ReadFrom(reader)
	if err != nil {
		return ""
	}
	newString := buf.String()
	// BUG: Not needed
	// _, err = fmt.Printf(newString) // incomplete arguments list
	// if err != nil {
	// 	return ""
	// }
	return newString
}

deze333 avatar Nov 01 '19 00:11 deze333