Besides the built-in + operator, there are more ways to concatenate the string. This recipe will describe the more performant way of concatenating strings with the bytes package and the built-in copy function.
Concatenating a string with writer
How to do it...
- Open the console and create the folder chapter02/recipe04.
- Navigate to the directory.
- Create the concat_buffer.go file with the following content:
package main
import (
"bytes"
"fmt"
)
func main() {
strings := []string{"This ", "is ", "even ",
"more ", "performant "}
buffer := bytes.Buffer{}
for _, val...