Junior — Middle
When was the last time you used a buffer for storing or exchanging data?
sobes.tech AI
Answer from AI
In Go, buffers are often used for temporarily storing data during reading or writing, as well as for exchanging data between components.
For example, the bytes package provides the Buffer type, which implements an in-memory buffer and supports read and write operations:
import (
"bytes"
"fmt"
)
func main() {
var buf bytes.Buffer
buf.WriteString("Hello, ")
buf.WriteString("world!")
fmt.Println(buf.String()) // Outputs: Hello, world!
}
Such a buffer is convenient for accumulating data before sending it over the network or writing to a file. The last time I used a buffer was when processing an HTTP request, where I needed to assemble the request body in memory before parsing.