How to concatenate two or more byte slices in Go?

You can use the bytes.Join() function from the bytes package to concatenate two or more byte slices in Go. Here's an example:

import ( "bytes" "fmt" ) func main() { slice1 := []byte("Hello, ") slice2 := []byte("World!") result := bytes.Join([][]byte{slice1, slice2}, nil) fmt.Println(string(result)) // Output: Hello, World! }

In this example, we have two byte slices slice1 and slice2. We pass these slices as a slice of byte slices to the bytes.Join() function, along with a separator (nil in this case). This will concatenate the slices and return a new byte slice result, which can then be converted to a string using string(result) for printing the combined result.