Go

Go

Made by DeepSource

Use (*bytes.Buffer).Reset instead GO-R1003

Anti-pattern
Minor

Truncate discards all but the first n unread bytes from the buffer but continues to use the same allocated storage. If n is 0, i.e., argument to Truncate, it is the same as Reset that resets the buffer to empty, and the latter is considered more idiomatic.

Bad practice

buf := &bytes.Buffer{}
// do some work
buf.Truncate(0)

Recommended

buf := &bytes.Buffer{}
// do some work
buf.Reset()